[Noob] Understanding & Accessing Pins/Data via Arduino Dock
I'm struggling to understand the relationship and interconnections between the Arduino Dock 2 and my Onion 2. Take a simple example of a gas sensor connected to Analog 0. I can write a program in the Arduino IDE to read this via Serial.read(A0) but how would access the value of A0 from inside OnionOS to lets say, push a value somewhere via curl. I was hoping someone can provide a high-level explanation or URL to some documentation that explains how to really wrangle the Arduino dock with the Onion? Maybe I should just be working with the onion dock if I want to control everything from inside linux with my familiar programming languages (Python, Node, etc). Thanks.
The main source of documentation for the Arduino Dock 2 is at the usual Onion documentary pages at https://docs.onion.io/omega2-docs/arduino-dock-2.html.
The main important thing to understand is that the ATMega chip is hard-wired to the Omega's UART1, I2C and SPI peripherals, see the 'Omega to ATmega MCU Connections' section.
Thus, an easy way to push measurement values from your Arduino to your Omega2 is to send them via one of these connections. The easiest one is UART. In your Arduino firmware, setup the normal serial interface, e.g.
Serial.begin(115200), then everything that is
Serial.println(..)is received on the Omega's
/dev/ttyS1interface (at that baudrate). See https://docs.onion.io/omega2-docs/uart1.html#uart1, section 'Using the screen Command'.
@Maximilian-Gerhardt - Thanks! That explains it. Then I assume it's possible to push values / read from the Onion in the other direction?
Yes, since UART is bidrectional, writing to the UART1 aka
/dev/ttyS1on the Omega2 willl send it to the Arduino, where you can read it with the normal
Serial.read()and associated methods.
You might be interested to know that 9600 8N1 is the default setting of UART1 (/dev/ttyS1) on Omega2(+).
Just wanted to thank everyone for helping me understand this. It's working great. I just need to get my head around the Linux side now. It works great with 'screen' - can send messages back and forth, but now I need the data from /dev/ttyS1 to get shoved into a curl POST as a line is captured. I'm thinking it'll look very similar to how I receive lines on the Arduino side (buffered char* terminated with \n\r etc). Anyone do this without pySerial?
Anyone do this without pySerial?
Why do it without the library that is specifically designed for it? Would be the easiest way.
You can also write a bash script which reads the data (using
read, refer here, here and here). Or a C program. I wrote a C program specifically for the Omega in that thread, implementing
read()until a newline should be fairly easy.
@Maximilian-Gerhardt - this is awesome!!! Thank you.