write a function that sends data to the QT Py, here's an example below for the variables I'm interested in (fed3.counter is a custom variable that I added to the FED3 library, yours will not have it):
void sendData() { //send session type and pellet count to qtpy
Wire.beginTransmission(8); // Address 0x08 is set in the sketch uploaded to the QT Py
Wire.write(String(fed3.FEDmode).c_str());
Wire.write(",");
Wire.write(String(fed3.counter).c_str());
Wire.write(",");
Wire.write(String(fed3.PelletCount).c_str());
Wire.write(",");
Wire.write(String(fed3.measuredvbat).c_str());
//Wire.write("\0"); // empty byte
Wire.endTransmission(8);
}
add to setup function:
add your custom function to the loop function whenever you want the QT Py to receive data. I currently send data after every FED3.Feed() function:
sendData();
- Coding and Setting up the Adafruit QT Py:
First, you will need to set up a Google Service account and the Google Sheet(s) that you want for each device. Follow these instructions from Random Nerd Tutorials.
Attached is my template sketch, which I hope is commented well enough to follow. Key things that you will need to do:
- add your own Google Sheet info
- add your own WiFi network info
- adjust to your own time zone
- remove my counter variable and ensure your dataIn matches the sendData from your FED3 FeatherM0
Troubleshooting:
Some of my QT Py devices have better wifi connectivity than others. They are not too expensive ($12.50 USD) so you could always replace the ones that are buggy.
The QT Py i2c address must be set by you in the QT Py sketch. Even if plugged in, it won't be detected on an i2c scan on the Feather M0 until you set the address. I arbitrarily set it to 8 (or 0x08 in i2c address syntax), but if for some reason you already have something at that address, you can set it to something else.
The bytes that are sent over the Wire function must be chars, so convert your variables into char. I've done this by converting all of my variables to Strings, then converting them to chars. Clunky, but seems to work so far and can be done in a single line.
-----------------
If you have any questions, suggestions, etc. please let me know! I just got this working a couple weeks ago so I'm still troubleshooting but thought I'd share as it has given me a lot of peace of mind and convenience to monitor my animals from afar.