Old V2 Adding a New Sensor - alanbjohnston/CubeSatSim GitHub Wiki
Testing the New Sensor
You are now ready to start adding sensors to the code.
For your sensor, look for example code on the Sparkfun website. You will most likely have to install some libraries in the Arduino IDE.
If you haven't already installed the Arduino IDE on your computer, install it now by following these steps https://github.com/alanbjohnston/CubeSatSim/wiki/V2-Pico-Software#installing-arduino-software
To install a new Arduino library, open Tools/Manage Libraries and the Library Manager will open after a few moments. In the search box, type the name of the library or the sensor then return and you will see some libraries listed. When you mouse over it, it will give an Install button. Click on Install to install it.
Once the library is installed, there will often be example code for you to try. Look under the menu File/Examples then scroll down to the bottom where Examples Custom Libraries are listed. First try compiling the example code by checking the Verify button (checkmark). This will verify that you have all the required libraries. If you don't get errors and you have connected the Qwiic connector from your sensor to the STEM Payload board, you can try to Upload the code by clicking the Right Arrow icon.
First, you will need to wire the sensor to your Pico and try the example code for the sensor.
Find a Qwiic cable that has female connectors on it that you can plug directly onto the Pico pins.
Wire it up as follows:
- Connect the pico pin GP4 (pin 6) to the Qwiic pin SDA (Blue wire)
- Connect the pico pin GP5 (pin 7) to the Qwiic pin SCL (Yellow wire)
- Connect the pico pin 3V3 (pin 36) to the Qwiic pin VIN 3.3V (Red wire)
- Connect the pico pin GND (pin 38) to the Qwiic pin GND (Black wire)
Plug the Qwiic cable into your Sparkfun sensor.
Open the Example code.
Add this line to the first line after void setup() inside the {
delay(10000);
So it is begins:
void setup()
{
delay(10000);
Look for the output in the Serial Monitor. It may take up to 30 seconds for your sensor to start functioning.
After you have tested the example code and verified then sensor works, you are ready to add the new sensor code.
Adding the New Sensor
In the Arduino IDE, open the Payload_BME280_MPU6050_XS.ino code and click on the tab "payload_extension.cpp" and you will see where you add the code for your sensor:
There is an example in Payload_BME280_MPU6050_XS_Extended that you can use as a template.
VERY IMPORTANT: Some example code has this in setup():
//Initialize sensor
if (mySensor.begin() == false)
{
Serial.println(F("Sensor not detected. Check connections. Freezing..."));
while (1)
; // Do nothing more
}
DO NOT include code like this in the payload_extension.cpp
file or it will freeze the rest of the Pico code and prevent any of the sensors from working. Instead, just print the error message but do not do the while (1) ;
statement.
Once you have added your code, simply compile and Upload to your Pico. You should see the new sensor at the end of the string in the Serial Monitor and in the APRS packet when it is decoded.
On the Raspberry Pi, you can also use the CubeSatSim/config -p
command to see the sensor data from the Pico.