help needed with Serial

Hi guys

im having trouble with serial comms on the arduino Uno, its a genuine arduino board.

my code is the following:

#include <AltSoftSerial.h>

AltSoftSerial altSerial;
void setup() {
  // put your setup code here, to run once:
altSerial.begin(9600);
 Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
altSerial.println("0");
 delay(1000);
altSerial.println("1");
 delay(1000);
 altSerial.println("2");
 delay(1000);
 altSerial.println("3");
 delay(1000);
 altSerial.println("4");
 delay(1000);
 altSerial.println("5");
 delay(1000);
}

When I record the recieved serial on a USB to Serial adaptor in putty I get the following:

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2018.12.02 11:07:40 =~=~=~=~=~=~=~=~=~=~=~=
fy=YÞey=Vë gy=³Þfy=YÞey=Vë gy=³

one thing I notice is that the RX LED on my usb to serial adaptor is always illuminated when connected to the arduino, this is not the case when used on any other project I have used it for, I have measured and there is 5V being constantly output from the arduinos TX pin.

Funnily, if I load the altsoftserial demo program onto two arduinos everything works as expected.

I have read that some people have had clock speed issues etc with the arduino, I have amde sure I have selected the arduino / genuino UNO in the boards section of the IDE and the right com port when uploading the sketch.

Im at a total loss, any help would be apreciated.

Thanks,

Your intentions are far from clear. Maybe this is just an intellectual exercise with no real goal in mind but, at a guess, you have too much hardware. If you delete all reference to altsoftserial and altserial, just use serial, and get rid of the USB adapter, Putty should deliver what you want - all presuming that is what you want..

Do you have puTTY set to communicate at 9600 baud?

pert:
Do you have puTTY set to communicate at 9600 baud?

yes, I have also tried all other standard baud rates just incase

Nick_Pyner:
Your intentions are far from clear. Maybe this is just an intellectual exercise with no real goal in mind but, at a guess, you have too much hardware. If you delete all reference to altsoftserial and altserial, just use serial, and get rid of the USB adapter, Putty should deliver what you want - all presuming that is what you want..

I have a device controlled by serial comms, the end goal is to have that controlled via an arduino with connected switches etc and the appropriate logic.
I can control the device in normal conditions and know the commands. So for now it is important that another device recieves the serial data (in this case putty) so that I can compare the incoming data from the arduino sketch and the known good commands. Then I can write the logic for the control.

Is the Serial - USB adaptor a Rs232 - USB or a TTL - USB adapter? An Arduino needs a TTL - USB adapter.

Also, have you a GND connection to the adapter as well as Rx and Tx?

For testing I would just send “Hello World” once per second so you get a chance to see if some of the characters are being received.

…R

Just to get this clear in my mind, you want to use altsoftserial to connect via a separate ttl-usb to your computer, what pins are your altsofserial rx-tx pins ?

Robin2:
Is the Serial - USB adaptor a Rs232 - USB or a TTL - USB adapter? An Arduino needs a TTL - USB adapter.

Also, have you a GND connection to the adapter as well as Rx and Tx?

For testing I would just send "Hello World" once per second so you get a chance to see if some of the characters are being received.

...R

https://www.moxa.com/product/UPort_1110.htm

these are the two adaptors that I have tried so far with no luck. The only hardware I have that seems to work is the pro mini with an FTDI on it.

Deva_Rishi:
Just to get this clear in my mind, you want to use altsoftserial to connect via a separate ttl-usb to your computer, what pins are your altsofserial rx-tx pins ?

That is essentially correct, although I dont care if I use altsoftserial, or the hardware serial on pins 0 & 1.
for altsoftserial im using pins 8 & 9 as per the docs I found online.

the result is exactly the same if I use the hardware serial or altsoftserial. The output in putty isnt as expected but is identical in both cases

and when you use the arduino IDE Serial monitor ? (i have used putty once or twice, but it didn't work as i expected for me..)

when i open the com port of the usb to serial adaptor with the IDE serial monitor I also get garbled nonsense

and using the Arduino Uno's USB ? using hwSerial ?

spruce_m00se:
these are the two adaptors that I have tried so far with no luck.

Both of them clearly state that they are USB- RS232 adapters. They are NOT suitable for an Arduino. RS232 voltage levels can damage an Arduino.

...R

spruce_m00se:
Funnily, if I load the altsoftserial demo program onto two arduinos everything works as expected.

I read over the top of that line before .. it does ? ah in between 2 Arduino's yeah it should... upto 57500 i got that to go as well. Now that i've clicked the links to your products and i saw the prices i was a tad schocked. for what you want you could use any of these
https://nl.aliexpress.com/wholesale?catId=0&initiative_id=SB_20181202030305&SearchText=usb+to+ttl
just be careful not to pick one that has a 'fake' prolific chip on there that might be difficult to install (the updated driver checks for genuine prolific) even a modified esp uploader would work.

Robin2:
Both of them clearly state that they are USB- RS232 adapters. They are NOT suitable for an Arduino. RS232 voltage levels can damage an Arduino.

...R

I had no idea that there was a difference between the serial port on an arduino and the rs232 ports, haivng read up on it, that also explains why the Rx light is always on.

I have purchased a convertor board based on a max232 chip. Hopefully that will do the trick

Just a follow up for completeness for future reference

I have purchased one of these:

it has this chip on it:
https://eu.mouser.com/datasheet/2/146/SP3238E_100_020111-535507.pdf

it now communicates as expected when recieving the serial data with the original MOXA brand usb adaptor
https://www.moxa.com/product/UPort_1110.htm

I still have no luck getting the end result of a specific device responding to my commands, but I suspect that is now a matter of syntax more than anything.