Understanding the Arduino OnionLibrary
-
I am currently fiddling around with building a datalogger using the Omega with the Arduino dock for gathering data like temperature, humidity, light level etc.
The sensors (currently a DHT22 and a light sensor) are hooked up to the Arduino part of the setup. I am running a cronjob on the Omega polling the Arduino for the data and writing it into a log. (Which at some pont in the future may be read by a Bottle server and displayed nicely on a mobile device.)
There is however some interference between the wire library I use and the OnionLibrary. I had a look into the sources and saw that the OnionLibrary contains a lot of code to manage NeoPixels (as well as requiring the NeoPixels library as well). I would very much avoid using it but still retain the ability to use the Omega for programming the ATMega. The wiki pages on that subject have just a rather short and (at least to me) cryptic advice to "make sure to build this functionality into your I2C handling ".
I am also not sure if I understand the inner workings of the code as sometimes things are called an address and other times data. In my understanding the only "address" is 0x08 for the I2C slave anything else sent and received is simply data consisting of a "register" and the actual data..
Am I right to assume that "listens for a write of 0xde 0xad when resetting" actually means "listens for a write of 0xde 0xad and on receiving this data performs a software reset within 15ms"?
If so, would it be sufficient to incorporate a handler in my sketch that, on receiving 0xde 0xad, performs a software reset? And how would I do that?
Thank you.
PS: I am aware that the sensors can be hooked up to the Omega directly but as far as I see there isn't just broad enough support on the Omega for the various types yet. Plus I would like to be able to just simply switch out the processing and logging part if the need arises (maybe to a RasPi or any other platform with I2C support).
-
Apologies that the explanation regarding the
0xde 0xad
reset command is unclear, I'll be touching up the wiki article and adding some examples.Regarding the address and data nomenclature:
- Each I2C device has it's own device address on the I2C bus, in this case the Arduino will have an address of
0x08
- Devices usually use a register abstraction for setting parameters and reading data, each register have their own address through which they are accessed
So for the Arduino Dock reset, you will need to send an I2C write to device
0x08
, to it's address0xde
and the data you write will need to be0xad
.@Sciscitor said:
If so, would it be sufficient to incorporate a handler in my sketch that, on receiving 0xde 0xad, performs a software reset? And how would I do that?
Yep, that's correct. I've added an example on how to accomplish this: https://github.com/OnionIoT/Onion-Arduino-Library/blob/master/Onion/examples/SketchWithoutLibrary/SketchWithoutLibrary.ino
Let me know how it goes and if there's any problems!
A small thing to note, we're working on updating the communication with the Arduino so this should be much simpler in the future, stay tuned!
- Each I2C device has it's own device address on the I2C bus, in this case the Arduino will have an address of
-
Thank you very much! I will be trying it out as soon as my time allows. I already coded something like that (but not quite, as it did not work). I will let you know if your code works.
Edit: Could not wait to test it and it works just fine! Thanks again!
-
@Sciscitor No problem, glad to help