Hi, I'm looking to take a serial input, modify it, and output it with an Arduino and I'm hoping to get some help.
For a bit of background, I'm trying to setup and show how an elliptical machine can be used for cycling apps like Zwift. The elliptical I have has a CSAFE port and I have a device called Gem Retro that takes the CSAFE output and sends it over bluetooth or ant+ to a device running Zwift or similar. This works except it doesn't send the necessary power (watts) information. It sends METs though, so I just have to somehow do the conversion on an Arduino that acts as an intermediary between the elliptical and Gem Retro.
Initially, I'm just trying to read in info from the CSAFE port. I have an RJ-45 cord coming out of the CSAFE port and have hooked up wire 4 (TX) to the RX pin on my Arduino. I've also hooked up the ground wire to my ground on Arduino. I'm only looking to receive so haven't hooked up anything else. I'm not sure if I have to also hook up VCC. Does this wiring sound right?
The code I'm starting with is as follows (borrowed from here, except switched to serial1 as I'm using a leonardo):
void setup() {
Serial1.begin(9600);
Serial1.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}
void loop() {
if (Serial1.available()) {
char c = Serial1.read(); //gets one byte from serial buffer
Serial1.println(c);
}
}
I upload the code to my Leonardo and then I open the serial monitor but nothing is coming up. Any idea what I might be missing?
I'd also be grateful for any input on this project at all.
You're not printing anything to the serial port so nothing will go out over USB. You're currently printing to the device that you receive your data from.
void setup()
{
// comms with serial monitor
Serial.begin(57600);
// for Leonardo, wait till a connection is established
while(!Serial);
Serial1.begin(9600);
// print to serial monitor
Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}
void loop()
{
if (Serial1.available())
{
// read from device
char c = Serial1.read(); //gets one byte from serial buffer
// print on serial monitor
Serial.println(c);
}
}
sterretje:
You're not printing anything to the serial port so nothing will go out over USB. You're currently printing to the device that you receive your data from.
void setup()
{
// comms with serial monitor
Serial.begin(57600);
// for Leonardo, wait till a connection is established
while(!Serial);
Serial1.begin(9600);
// print to serial monitor
Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}
void loop()
{
if (Serial1.available())
{
// read from device
char c = Serial1.read(); //gets one byte from serial buffer
// print on serial monitor
Serial.println(c);
}
}
He is reading from Serial1 and writing to Serial .
@sterretje, I see my mistake now, thanks for the fix.
I now get some data as the machine starts to work:
serial delimit test 1.0
a
a
{
{
a
{
L
⸮
⸮
⸮
⸮
This is good, though I have no clue what it means and it only shows at startup and nothing gets updated as it runs. I tried different baud rates in hopes it might become something more understandable, but no luck. By the way, as far as baud rate, why 57600 for Serial but 9600 for Serial1?
@ieee488, the voltage coming off pin 5 is something like 7.5V. Are you sure I need to do something with this? And if so, what pin on the Arduino would I connect this too. I already have a power source for the Arduino, so not sure why I would need another one. Perhaps it is for some kind of reference?
Thank you all for your help on this. I'm pleased to be getting some response from the machine, though not sure where to go from here. Perhaps there has to be some kind of hand shake or something, but the wikpidia page for CSAFE doesn't seem to think it is essential. Hope you can help some more.
Thank you kindly,
Sam
P.S. I don't think I'm using the @symbol correctly. I read somewhere you have to do something like this: "@?". But I don't know where to find member numbers. Please let me know the proper way to do this if you know.
@ieee488, the voltage coming off pin 5 is something like 7.5V. Are you sure I need to do something with this
We are all sure that you need to do something with that. Otherwise, you will destroy the Arduino, if you haven't already. Here is what the web page you linked says:
Most of the pins from the RJ-45 plug should be connected to a normal RS-232 interface configured for an asynchronous communication mode of 9600 baud with 8 data bits, 1 stop bits and no parity.
Translation: For Arduino, you MUST use an RS232 to TTL voltage level adapter. Example. And, as you see above, the Baud rate is 9600.
Okay, I'm starting to understand a bit better. The Rx/Tx signals are relative to the voltage, and so they need go through a converter (please correct me if this is wrong). I'll order the converter. Once it's connected, I'll hook up ground to ground and Tx (from converter) to Rx on Arduino. Any other connections I'll need to be able to properly read from the CSAFE port?
The next step (after understanding and modifying the output) will be sending the altered info to the gym retro unit. I think I'll have to convert back to RS232. If I understand correctly, the same Sparkfun board works in reverse, so I can just use that again. Please correctly me if I'm wrong.
Are there any other components anyone can think of I'll likely need to make this all work?
void setup()
{
// comms with serial monitor
Serial.begin(57600);
// for Leonardo, wait till a connection is established
while(!Serial);
Serial1.begin(9600);
// print to serial monitor
Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}
void loop()
{
if (Serial1.available())
{
// read from device
char c = Serial1.read(); //gets one byte from serial buffer
// print on serial monitor
Serial.println(c);
}
}
After the machine turns on, the shift register Tx light turns solid red and the Rx turns solid green, but nothing comes up in the serial monitor except that first line, "serial delimit test 1.0".
Note: the module you are using is not a "shift register". It is called either an RS232-TTL adapter or RS232-TTL level shifter.
It really is not clear what you have done. Please post a hand-drawn wiring diagram showing the connections, clearly labeling all the pins. Note that there are two different connectors; the 9 pin DB9 connector, and the 4 pin board edge connector.
You should be connecting the adapter to the CSAFE port using a DB9 male connector and cable. Is that what you did?
Keep in mind that the Arduino pins may be have burned out previously by connecting to the RS232 voltage levels.
I have an RJ45 cable coming from the CSAFE port. I've spliced it and connected as shown in the diagram below. Also shown are the connections I've jumpered to the Arduino Leonardo board.
You helped me realize a mistake I was making. I've fixed it now and I'm getting some output in the serial monitor (below), but don't understand how to read it. Also, it doesn't keep running but seems to stall. Any ideas?
Wikipedia says 9600 baud rate, which is what I've been using.
Any suggestions on how to fix the communication protocol if that's the problem?
I have an Arduino DUE I could try with. I get confused with Serial1 VS Serial for Leonardo VS other boards. Would the code posted work just as well on the DUE?
"Serial" on the Leonardo is a virtual COM port on the PC or Mac. You can use it only for uploading or serial monitor communications. Serial1 is the hardware serial port that you can use for other devices.
Is this still the case? If so there may be a wiring error.
the shift register Tx light turns solid red and the Rx turns solid green
My interpretation of the RS232 adapter schematic and your confusing wiring diagram requires that the Rx LED be OFF.
Many machines that communicate using RS232 don't "talk" unless commanded to do so via the RS232 port. If that is the case with your machine, you need to send it appropriate commands via the Arduino.
The lights are no longer solid green and red, I was making a mistake you alerted me too. The rather poor schematic I uploaded is what I am using now and getting some data, just no clue what it means despite trying different baud rates, and it halts.
I've also tried an Arduino Due but it just writes the first line "serial delimit test 1.0" and then nothing else. I think the code would have to be different but I'm not sure how.
The wikipedia article on CSAFE ports says "handshaking" shouldn't be necessary. But perhaps there does have to be some instructions sent.
Any suggestions of a forum where I might find someone who has worked with CSAFE ports before?