Serial1 config params similar to Arduino Serial [SOLVED]

Hi,

I’m currently getting started with my newly arrived photon. I implementing a Serial based control solution for my projector.
For this connection I need the following configuration settings:
Communication condition
Baud rate : 9600bps
Data length : 8 bits
Parity : No
Stop bit : 1 bit
With the original Arduino I was able to make this work, but I haven’t seen the “config” option for Serial1.begin like the Arduino has.

If you just just write

  Serial1.begin(9600);

Your desired settings are being used, since they are default on Particles, too.
Any other settings are not yet easily available, tho’ :weary:

1 Like

Hm okay this is unfortunate… I hoped iit would work with 3.3v too but if the serial connection is expected to work similarly, this iis he only difference :confused:

Sorry, I don’t get the connection to 3.3V.

Sure the RX/TX pins on the Photon are 3.3V (although 5V tolerant - but check specs to avoid blasting them ;-)), but the settings you originally posted refered to the protocol and not the voltage.
On Arduino you can’t set the voltage either. Either it’s 3.3V or 5V and to connect different voltage levels you should use hardware level shifting - unless you exactly know that you won’t damage anything :point_up_2:

I’m using a RS232 to Serial adapter for the connection on Arduino I used the 5v line to drive the adapter and it worked. Now I’m using 3.3v since I didn’t plan to blast the photon :wink: I don’t have any details about the requirements of the adapter which is why I thought I could try just driving it with 3.3v.
So I guess I’ll have to buy a level shifter in order to use 5v?

You won’t need to if you look at the datasheet :wink:
But as I’ve just seen, that’s easier said than done, since the link seems to have vanished from the docs nav bar
http://docs.particle.io/photon/hardware/

It says there

All pins except A3 and DAC are 5V tolerant (when not in analog mode). If used as a 5V input the pull-up/pull-down resistor must be disabled.

So, on the Photon it should be save to use RX/TX against 5V.
If you want to be extra cautious you could add a red LED on the RX pin or a voltage divider or make your own RX level shifter with a common transistor.


Got any idea about the make of your RS232-TTL-adapter? Maybe friend Google can tell us a story about it :wink:

@alterschw3de, @ScruffR is correct and I’ve connected directly from RX/TX on the Core and Photon to an Arduino without any problems.

Okay, so thanks guys for the first few hints.
I had not enough time to answer properly, but here goes :smile:

The RS232 to Serial Adapter is based on a MAX3232 chip, it’s supposed to run with both 3.3 and 5v.

The other end is an Epson TW3200 with the following documentation:

And I’m using the following code:

void setup() 
{
  Serial1.begin(9600);  // open serial over TX and RX pins
  Spark.function("projector", controlProjector);
}
    
void loop() { }
    
    
    
int controlProjector(String command)
{
  Serial1.print(command); 
  return 1;
}

Now I’m sending via Postman (in Chrome) the String “PWR ON” via the RST API to api.particle. But nothing happens…

First of, try to parallel print your command to Serial, to see what you should get out of Serial1.

Next you might want to use Serial.write() instead to prevent any (unexpected) manipulation of your incoming string - since you are only sending a “readable” string, this should not be a problem, but to be on the save side :wink:

Next you could check your TX data by wiring it back to Photons RX pin and read the data inside loop() and write that over to Serial again.

If all that works, you’ve established that your Photon is doing everything right.

Then it might either be your RS232-TTL adapter or your receiving device.

To check this, you might be able to find one of these ancient devices that have an inbuilt RS232 port or can get hold of a logic analyzer or an oszillograph.

2 Likes

Hi ScruffR,

thanks for your help. Using Serial.write solved the problem. I already tried just invoking a method but hard coding the String so this was out of the question, and the TTL adapter worked with the arduino tand the receiving device.

Now I’m using
command += “\n\r”;
Serial.write(command);
and it’s working perfectly. Thanks so much!

2 Likes

Could it be that your Arduino code used Serial1.println() instead of Serial1.print()?

I’m not sure, I lost the Arduino code :smiley: But I tested with print +"\n\r" and with println before and it didn’t work.

So for the next project I’ll use Serial.write directly :smile:

Thanks again.

1 Like