bash -> arduino
| Author | Message | ||||
| Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 6103 |
I could use some help on how to do things in bash... First some background info... I am using Putty as a terminal (linux) to control micromites and arduino's through serial port (either /dev/ttyUSBx or /dev/ttyACMx). On arduino's (UNO) I have a tinybasic interpreter running that allows setting digital outputs and read inputs, mainly because you can buy arduino shield cheap, and can build a "stupid" peripheral cheap. The interpreter can run programs, but can also directly execute command line commands. And that is exactly what is used here. But this question is not about the interpreter, or the Arduino. It is about sending data to a serial port from bash (linux shell). For a quick test project at work I decided to write some expect scripts (dialog) for a simple test setup, controlling the I/O through the arduino. Basically I send strings to serial port, which the arduino processes, and ignore the feedback (the basic interpreter sends a prompt after completion of the command.) This works "unreliable" at best, and I want to find out why. #!/bin/bash #open serial port to arduino #sudo stty -F /dev/ttyUSB0 9600 cs8 -parenb -cread -crtscts clocal -hupcl sudo stty -F /dev/ttyUSB0 9600 -hupcl #let arduino wake up sleep 5 for i in {1..1000} do echo $i echo "dwrite 13,1" > /dev/ttyUSB0 sleep 0.5 echo "dwrite 13,0" > /dev/ttyUSB0 sleep 0.5 done This is basically the script that shows what I am trying to do. Very simplified, just the basics. Pulse output 13 of the arduino. I have been trying to open the serial port with all kinds of options, but none make it work reliable. But... when I open Putty with 9600 baud on /dev/ttyUSB0 all works brilliant. I know Putty and my script both access the same serial port. But Putty does something to the serial port that makes it work. And I can't find out what that is. Even when I close Putty again, it keeps working great. Even if I shut down the script, and restart it all is fine. Until I reboot the system (in my case a Pi 4 running raspbian). Is there anyone that has any experience with things like this. Sending serial data to a slave from command line in linux.? PicomiteVGA PETSCII ROBOTS |
||||