Serial communication to/from Photon over Wifi

I would like to use a photon to control devices over Wifi. The computer interface uses serial. I have to use the serial.begin code and establish a serial connection to the controller at the present time but would like to make this Wifi. To ensure I am clear, I communicate with the microcontroller over a serial com port via hard line. To make this wireless I am sure I would need a COM to wireless driver (much like we see with bluetooth com ports) but would like the proton to understand. I have to use a COM port on the PC and have to use the Serial() protocol on the microcontroller. This method works flawlessly over hard line but would like to make this wireless. Does anyone have any suggestions? I reviewed this post: Communicating directly from PC to a Photon via Wifi did not gather any useful information.

Actually there is a lot of useful info in that thread - it’s just not what you want to read :wink:
WiFi (IEEE 801.11) is not the best way to do this since it’s a network standard not really meant to be used this way.
Sure one could “abuse” it that way but there are other options especially for your case (as pointed out in the other thread) - e.g. Bluetooth SPP, Virtual Wire 433MHz, …

Hmm, I may have to use bluetooth if the tech isn’t here yet to natively convert. The other thing I was looking at is a ESP8266. I think that will cover me on the wifi to serial conversion but im not sure how to convert serial to wifi without the use of a second one. I do not want to use a second set of hardware that is connected to the computer. I believe that counts 433 out. My idea is to not have to use any additional hardware to pretty much any computer. We all know most general computers have network access. Any more info is appreciated.

If you are not using additional hardware on the computer, have you already figured out how to get the computer to send the serial commands over wifi?

The photon can take care of converting from Wifi back to serial no problem. Using a TCP to serial bridge will take care of that.

I would like to know more about the wifi back to serial. Are you saying use a ESP8266 for the TCP to serial bridge or is that unnecessary due to software? Serial to Wifi will hopefully be handled by this or something very similar.

Good - I was going to suggest a virtual COM port if you weren’t already using that.

I’d suggest using a Photon for the WiFI > Serial conversion. :smile:

The Wifi > Serial conversion, is it hardware or software and where might I find the device/code?

The WiFi -> Serial is in firmware - you write an application that does the transfer.

The virtual com port is creating a TCP Server, So your photon has to connect to that server, then redirect any data that is read from the server to the serial port.

This is just pseudo-code, but should give you the outline:

TCPClient tcp;
// fill in the address of the TCP server for the virtual COM port
uint8_t server = { 10, 0, 0, 1 };
uint16_t port = 53;

void loop()
    if (!tcp.connected()) {
        tcp.connect(server, port);

   if (tcp.available()) {
   if (Serial.available()) {

That’s the bare bones of the application to connect to the server, and transfer data between the TCP server and the local serial port.

1 Like

Thanks for the advice. That’s almost exactly what I want to do, my next dilemma is the code I use actually takes input from serial and changes pin states accordingly so to adapt it to my code, it appears I just need to change what would be to Can you confirm that would work or is the tcp protocol still incorrectly formatted? I mainly hope this will work so that I may change a library my code uses and everything else will filter down. P.S. I have to use serial format on both ends due to computer program interfaces.

I want to do something very similar. I have seen a circuit that basically takes a RS-232 serial connection into an arduino which converts that into a TTL which it then hands over to an FTDI USB device, so that it can be read on the PC. I have previously used TTL to ethernet adaptors to send serial information into my network.

In the case of my serial to ethernet adaptors, USR-TCP232-E or USR-TCP232-T, I read the serial data by making a telnet connection to a server that I configure on the device.

But the more I think about it, the more I am convinced I could use a Photon to do the whole lot.

How would I achieve that?

This question is too open to be answered concisely :wink:

Yes, that should be doable with only a Photon, but what pieces of the picture are you missing were we could help you out?

The topics to investigate in the docs might be Serial (USB serial interface), Serial1 (TTL RX/TX serial interface) and TCPClient (TCP connection with telnet).

I’ll look into that. But if I just wanted to read the serial traffic coming in on an analogue input via the USB port, then presumably I just need to be able to convert the serial input and print that to the Serial terminal?

Probably, but your mention of ethernet adaptors, TCP and telnet suggested that you’d also wanted these fields covered :wink:

Want to get the basic working first before I get too excited. So if I am able to converted the incoming analogue signal into a TTL stream, can I just direct that TTL stream to Serial and expect to see the serial data on the PC connected via the USB port? I know an FTDI device is able to take TTL input and convert it to usb serial data but is the Photon able to as well? Would I need to use Serial.print or Serial.write to see the serial data for the TTL input on the PC console?

How would you do that?
What kind of analog signal are we talking about?
What would this TTL stream derived from the analgo signal look like?

But in general the answer to your question is: “Yes, this is doable”

That’d depend on the answer to my last question.

i am trying to read an eBUS system that has logical 0 = 9–12 volt and logical 1 = 15–24 volt (typical: 20 V)

Now I can read those voltages on one of the Photon analogue pins and write out a corresponding Digital High or Low on one of the Digital pins, which if I fed into a FTDI usb interface would give me a serial output on the PC. But with the Photon I felt it was completely unnecessary to have another FTDI interface as the photon can already talk to the PC via it’s own USB port. So the question is how do I write the Digital High and Low to the Serial such that I can read the Serial output on a PC via the Photon’s USB port.

Since your signals are outside of the specs for analog or digital pins you’ll need some external circuitry to bring that signal into an acceptable range, I’d design my external circuit in a way that you directly feed into a digital pin with no need to “calculate” HIGH/LOW from an analog reading.
And once you’ve got that digital state “inside” your Photon (e.g. on D7), you’d just
Serial.printlnf("Read state %s", digitalRead(D7) ? "HIGH" : "LOW");
or anything else you’d want to send to your PC depending on the pin state.

1 Like

I was simply going to use a voltage divider and get the voltage down to about +2 (low) and +3 (high) which I would read on the analogue pin.

If you look at the STM32 datasheet you’ll see that digital inputs have a threshold that will allow you to digitalRead() these voltages as HIGH/LOW direct.

@ScruffR, finding the right mix of resistors to work with 9-12v / 15-24v ranges to get a logical ‘0’ or ‘1’ is not proving easy. It may be necessary to use an open-collector output comparator powered by 24v. That way, a “true” logical level can be achieved while protecting the STM32 inputs. You could use a quad comparator like the LM339 or the single comparator LM311. A voltage divider could be set for just below the 15v minimum “high” voltage and the open collector connected to a pull-up to 3.3v and a GPIO pin. :grinning:

1 Like