[Wiltshire] Any Arduino serial comms experts out there?
Robert Longbottom
RobertCL at iname.com
Wed Feb 19 17:56:06 UTC 2020
Some of the more recent UNOs (and maybe other Arduinos) reset when you
connect to the serial port and I think maybe they reset when you
disconnect as well. It looks like the C program is closing the serial
port when it exits, which will probably be resetting the Arduino and so
it will briefly blink one of the LEDs and go back to the start state
with the LED off.
I've never tried to disable this behaviour, but it looks like it's
possible. A few links that google threw up:
https://arduino.stackexchange.com/questions/38468/disable-reset-when-com-port-connected-disconnected
This one suggests setting the flow control to None on the serial port
may work (you might already be doing this in your C program, but I'm not
familiar enough with C and serial ports to be sure):
https://arduino.stackexchange.com/questions/439/why-does-starting-the-serial-monitor-restart-the-sketch
It would make sense for it to be this reset on close thing though, if it
doesn't do it when you leave the Arduino serial monitor open. I guess
you could also check by adding a delay before the close in you C program
and you should see the LED come on and then go off again as the C
program exists.
Cheers,
Rob.
On 19/02/2020 17:39, David Fletcher via Wiltshire wrote:
> I'm trying to communicate between a Linux Mint 17 desktop and a UNO via
> the USB.
>
> With the following sketch loaded into the UNO:-
> #define LIGHTPIN 6
> bool
> // Flag to announce character received
> NewChar
> ;
>
> char
> InChar
> ;
>
> void setup()
> {
> NewChar = false;
> // initialize the digital pin as an output.
> pinMode(LIGHTPIN, OUTPUT);
> // initialize serial:
> Serial.begin(9600);
> }
>
> void loop()
> {
> // print the string when a newline arrives:
> if (true == NewChar)
> {
> if ('L' == InChar)
> {
> // Make the LED Light
> digitalWrite(LIGHTPIN, HIGH);
> }
> if ('D' == InChar)
> {
> // Make the LED Dark
> digitalWrite(LIGHTPIN, LOW);
> }
> NewChar = false;
> }
> }
>
> /*
> SerialEvent occurs whenever a new data comes in the
> hardware serial RX. This routine is run between each
> time loop() runs, so using delay inside loop can delay
> response. Multiple bytes of data may be available.
> */
>
> void serialEvent()
> {
> if (Serial.available())
> {
> // get the new byte:
> InChar = (char)Serial.read();
> NewChar = true;
> }
> }
>
> I can use the serial monitor of the Arduino workbench to send L and D to
> switch an LED on pin 6 on and off. OK so far, but ultimately I want to
> send commands and receive data from a C programme on a headless server
> so next I tried the example code from here:-
> https://github.com/xanthium-enterprises/Serial-Port-Programming-on-Linux/blob/master/USB2SERIAL_Write/Transmitter%20(PC%20Side)/SerialPort_write.c
> There's a lot more code here than is in the sketch so I've just included
> the link. When I replace the "A" in write_buffer at line 104 with "L"
> and "D" and recompile, it works but ONLY if the workbench serial monitor
> is open. If not, all that happens is one of the LEDs on the UNO board
> flickers a bit and the one I want to switch on/off always turns off, as
> if the UNO is actually doing a reset.
>
> Does anybody know what the magic incantation is, please? I've checked
> what I think are the usual things i.e.
> ls -l /dev/ttyUSB*
> crw-rw---- 1 root dialout 188, 0 Feb 19 17:32 /dev/ttyUSB0
> and
> groups
> dave adm tty dialout sudo vboxusers
>
>
More information about the Wiltshire
mailing list