I am pretty new to XOD and microcontrollers in general and I was trying to use data from 3 different sensors which use i2c to produce an air quality index(and maybe actuate the results with some LEDs). I have already finished this mini-project using the Arduino IDE with some downloaded libraries but I can’t quite figure out how to implement the same project using XOD since I have very limited knowledge of I2C communication. Is it possible that I can access some readily written library without diving into all the details and specifications of I2C?
-The sensors I am trying to use are,
–Wuhan Cubic CM1109 CO2 Sensor
– Sensirion SHT31
– Sensirion SGP30
I’m not seeing any nodes or libraries specifically for those devices, but there are i2c nodes in xod/i2c in the project browser that implement basic i2c functions and can be chained together to implement i2c communication for specific devices. This would basically require converting IDE code into the appropriate i2c nodes. This will probably not be trivial, but once completed, you will have your own library for those devices that you could then share with others.
In General: I just got multiple different I2C devices on the same BUS… Check out the solution to this recent post. The key is not crash the device communications into each other. There are several ways to do this. The simplest is to make a continuous daisy chain…
Now, you need a library in XOD… You’ve got to make your own, or maybe one of the XODERS can adapt it for you. You gotta start with the Arduino IDE Library from GitHub… (Assuming you can’t or don’t want to do what qweimer was talking about, which is fairly complex)
Here’s a recent example, that’s also fairly complex, using I2C, that Wayland made (bless his soul)…
In general, there’s some info on adapting libraries from Arduino libraries
Once you know what you’re doing, then it’s trivial to adapt a library. However, I actually haven’t mastered it… even after working on it for at least a week and reviewing waylands work.
I would recommend linked web addresses to 1) the libraries you need on GitHub, 2) the Devices you’re using… If somebody can do it, then they might. Especially, if your equipment could be very useful to other XODERS.
Alternatively, look at other devices that already have XOD libraries
Thanks for the advice! At first, I was quite stumbled with the absence of an XOD library since I do not have any programming background either aside from some C programming that I had done in the past. I tried to figure out adapting the Arduino library for XOD using C++, but it turns out the i2c functions in XOD are quite simple! I was able to finish my project in 2 days without any background in basically anything
P.S. Sorry for the late reply, I was trying to figure out how far I can go
Edit: The basic instructions in the XOD documentation helped a lot.
Here are some patches I created:
–Wuhan Cubic CM1109 CO2 Sensor
They still miss many features that the sensors are capable of(calibration, setting baselines etc.) but they got the job done when it comes to reading and outputting measurements. Any help on my code’s optimization is still much appreciated
Using SEND signal to toggle flip-flop to start continuously performing an action is probably not a good idea. Usually this would be an UPD pin to run the write/read process one time. Setting the UPD pin to LOOP would basically do what you have coded (but might run too often). Dropping the clock/flip-flop would be even more important if you were trying to create nodes to share with others; you can always add a clock node to continuously pulse the UPD pin outside this node.
I see. Can you specify which nodes I can use in this context that has a UPD pin? (I don’t really remember running into such a pin in the nodes I’ve tried using). Also, I can see intuitively why the flip-flop/clock combination may not be a good practice but I don’t get the exact reason(speed, applicability, storage usage, readability etc.)
Thanks again for the feedback.
UPD is just a different label. Your SEND pin is not really triggering a send as much as it is triggering an update of the output pins for the node; except as you have it programmed it is actually a “start updating output” pin. Part of the problem with this is that you have 2 devices on your I2C bus. If you have nodes auto-updating both of them, there is no way to prevent an attempt to communicate to both devices at the same time. If you just rename your pulse SEND pin to UPD, then tie it directly to begin-transmission-SEND and delete the clock & flip-flop, it will behave more like existing sensor nodes. If you really want it to update every second, you can put a clock node outside your sensor node & connect it to the UPD pin, but it might be better if you added a DONE (pulse) pin to your node and tie it to the last read-byte-DONE. This would allow you to UPD your sensor, and tie the DONE pin to the UPD pin of the next sensor so you know only one sensor is being updated at a time (similar to how you have read-byte daisy-chained in your node so you know each read finishes before you start the next one).
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.