Components and supplies
Gravity Μαγνητόμετρο Τριπλού Άξονα - BMM150
Gravity I2C HUB
PLA filament
3.7 V LiPo Battery
Solar Lipo Charger (3.7V)
FireBeetle Cover - LoRa Radio 433MHz
Gravity I2C BMI160 6-Axis Inertial Motion Sensor
6 volt 3.5 watt solar panel
Gravity GNSS GPS BeiDou Receiver Module - I2C&UART
FireBeetle 2 ESP32 C6 - Wi-Fi 6, Bluetooth 5, Solar-Powered
Tools and machines
Soldering kit
Friend with a 3D printer
Apps and platforms
Blender
VS Code
Matlab Simulink
Arduino IDE 2.0 (beta)
Project description
Code
Code
cpp
The first version of the code
1//HC1-A-V.1.00.3 2 3// mpla.code 4 5//----------------------------------------------------------------------------------------------------------------------------- 6 7#include "DFRobot_GNSS.h" 8#include "DFRobot_BMM150.h" 9#include <DFRobot_BMI160.h> 10 11 12//----------------------------------------------------------------------------------------------------------------------------- 13 14 15#define I2C_COMMUNICATION //use I2C for communication, but use the serial port for communication if the line of codes were masked 16 17#ifdef I2C_COMMUNICATION 18 DFRobot_GNSS_I2C gnss(&Wire ,GNSS_DEVICE_ADDR); 19#else 20 21#if defined(ARDUINO_AVR_UNO) || defined(ESP8266) 22 SoftwareSerial mySerial(4, 5); 23 DFRobot_GNSS_UART gnss(&mySerial ,9600); 24 #elif defined(ESP32) 25 DFRobot_GNSS_UART gnss(&Serial1 ,9600 ,/*rx*/D2 ,/*tx*/D3); 26 #else 27 DFRobot_GNSS_UART gnss(&Serial1 ,9600); 28 #endif 29#endif 30 31//----------------------------------------------------------------------------------------------------------------------------- 32 33//When using I2C communication, use the following program to construct an object by DFRobot_BMM150_I2C 34/*! 35 * @brief Constructor 36 * @param pWire I2C controller 37 * @param I2C address 38 * i2c Address select, that CS and SDO pin select 1 or 0 indicates the high or low respectively. There are 4 combinations: 39 * I2C_ADDRESS_1 0x10 (CS:0 SDO:0) 40 * I2C_ADDRESS_2 0x11 (CS:0 SDO:1) 41 * I2C_ADDRESS_3 0x12 (CS:1 SDO:0) 42 * I2C_ADDRESS_4 0x13 (CS:1 SDO:1) default i2c address 43 */ 44DFRobot_BMM150_I2C bmm150(&Wire, I2C_ADDRESS_4); 45 46//When using SPI communication, use the following program to construct an object by DFRobot_BMM150_SPI 47#if defined(ESP32) || defined(ESP8266) 48 #define BMM150_CS D3 49#elif defined(__AVR__) || defined(ARDUINO_SAM_ZERO) 50 #define BMM150_CS 3 51#elif (defined NRF5) 52 #define BMM150_CS 2 //The corresponding silkscreen on the development board is the pin P2 53#endif 54/*! 55 * @brief Constructor 56 * @param cs Chip selection pinChip selection pin 57 * spi Connection method 58 * (SDO<-->MISO) (SDI<-->MOSI) 59 * (SCK<-->SCK) (PS<--> GND) 60 * (CS<-->CS customize pin) 61 */ 62//DFRobot_BMM150_SPI bmm150(/*cs = */BMM150_CS); 63 64 65//----------------------------------------------------------------------------------------------------------------------- 66 67DFRobot_BMI160 bmi160; 68const int8_t i2c_addr = 0x69; 69bool readStep = false; 70 71#if defined ARDUINO_AVR_UNO || defined ARDUINO_AVR_MEGA2560 || defined ARDUINO_AVR_PRO 72 //interrupt number of uno and mega2560 is 0 73 int pbIn = 2; 74#elif ARDUINO_AVR_LEONARDO 75 //interrupt number of uno and leonardo is 0 76 int pbIn = 3; 77#else 78 int pbIn = 13; 79#endif 80/*the bmi160 have two interrput interfaces*/ 81int int1 = 1; 82int int2 = 2; 83 84//----------------------------------------------------------------------------------------------------------------------- 85 86void stepChange() 87{ 88 //once the step conter is changed, the value can be read 89 readStep = true; 90} 91 92//----------------------------------------------------------------------------------------------------------------------- 93 94void setup() 95{ 96 Serial.begin(115200); 97 while(!gnss.begin()){ 98 Serial.println("NO Deivces !"); 99 delay(1000); 100 } 101 102 gnss.enablePower(); 103 104 gnss.setGnss(eGPS_BeiDou_GLONASS); 105 106 107 // gnss.setRgbOff(); 108 gnss.setRgbOn(); 109 // gnss.disablePower(); // Disable GNSS, the data will not be refreshed after disabling 110 111 112//---------------------------------------------------------------------------------------------------------------------- 113 114 115 Serial.begin(115200); 116 while(!Serial); 117 while(bmm150.begin()){ 118 Serial.println("bmm150 init failed, Please try again!"); 119 delay(1000); 120 } Serial.println("bmm150 init success!"); 121 122 /**! 123 * Set sensor operation mode 124 * opMode: 125 * BMM150_POWERMODE_NORMAL // normal mode Get geomagnetic data normally 126 * BMM150_POWERMODE_FORCED // forced mode Single measurement, the sensor restores to sleep mode when the measurement is done. 127 * BMM150_POWERMODE_SLEEP // sleep mode Users can visit all the registers, but can't measure geomagnetic data 128 * BMM150_POWERMODE_SUSPEND // suspend mode At the time the sensor cpu doesn't work and can't implement any operation. 129 * Users can only visit the content of the control register BMM150_REG_POWER_CONTROL 130 */ 131 bmm150.setOperationMode(BMM150_POWERMODE_NORMAL); 132 133 /**! 134 * Set preset mode, make it easier for users to configure sensor to get geomagnetic data 135 * presetMode: 136 * BMM150_PRESETMODE_LOWPOWER // Low power mode, get a small number of data and take the mean value. 137 * BMM150_PRESETMODE_REGULAR // Regular mode, get a number of data and take the mean value. 138 * BMM150_PRESETMODE_ENHANCED // Enhanced mode, get a large number of data and take the mean value. 139 * BMM150_PRESETMODE_HIGHACCURACY // High accuracy mode, get a huge number of data and take the mean value. 140 */ 141 bmm150.setPresetMode(BMM150_PRESETMODE_HIGHACCURACY); 142 143 /**! 144 * Set the rate of obtaining geomagnetic data, the higher, the faster (without delay function) 145 * rate: 146 * BMM150_DATA_RATE_02HZ 147 * BMM150_DATA_RATE_06HZ 148 * BMM150_DATA_RATE_08HZ 149 * BMM150_DATA_RATE_10HZ (default rate) 150 * BMM150_DATA_RATE_15HZ 151 * BMM150_DATA_RATE_20HZ 152 * BMM150_DATA_RATE_25HZ 153 * BMM150_DATA_RATE_30HZ 154 */ 155 bmm150.setRate(BMM150_DATA_RATE_10HZ); 156 157 /**! 158 * Enable the measurement at x-axis, y-axis and z-axis, default to be enabled, no config required, the geomagnetic data at x, y and z will be incorrect when disabled. 159 * Refer to setMeasurementXYZ() function in the .h file if you want to configure more parameters. 160 */ 161 bmm150.setMeasurementXYZ(); 162 163 164 165 166//------------------------------------------------------------------------------------------------------------------- 167 168 169 Serial.begin(115200); 170 delay(100); 171 172 //set and init the bmi160 i2c address 173 while (bmi160.I2cInit(i2c_addr) != BMI160_OK){ 174 Serial.println("i2c init fail"); 175 delay(1000); 176 } 177 178 //set interrput number to int1 or int2 179 if (bmi160.setInt(int2) != BMI160_OK){ 180 Serial.println("set interrput fail"); 181 while(1); 182 } 183 184 //set the bmi160 mode to step counter 185 if (bmi160.setStepCounter() != BMI160_OK){ 186 Serial.println("set step fail"); 187 while(1); 188 } 189 190 //set the bmi160 power model, contains:stepNormalPowerMode,stepLowPowerMode 191 if (bmi160.setStepPowerMode(bmi160.stepLowPowerMode) != BMI160_OK){ 192 Serial.println("set setStepPowerMode fail"); 193 while(1); 194 } 195 196#if defined ARDUINO_AVR_UNO || defined ARDUINO_AVR_MEGA2560 || defined ARDUINO_AVR_LEONARDO || defined ARDUINO_AVR_PRO 197 //set the pin in the board to connect to int1 or int2 of bmi160 198 attachInterrupt(digitalPinToInterrupt(pbIn), stepChange, FALLING); 199#else 200 attachInterrupt(pbIn, stepChange, FALLING); 201#endif 202 203 Serial.println(pbIn); 204} 205 206//------------------------------------------------------------------------------------------------------------------- 207 208void loop() 209{ 210 sTim_t utc = gnss.getUTC(); 211 sTim_t date = gnss.getDate(); 212 sLonLat_t lat = gnss.getLat(); 213 sLonLat_t lon = gnss.getLon(); 214 double high = gnss.getAlt(); 215 uint8_t starUserd = gnss.getNumSatUsed(); 216 double sog = gnss.getSog(); 217 double cog = gnss.getCog(); 218 219 Serial.println(""); 220 Serial.print(date.year); 221 Serial.print("/"); 222 Serial.print(date.month); 223 Serial.print("/"); 224 Serial.print(date.date); 225 Serial.print("/"); 226 Serial.print(utc.hour); 227 Serial.print(":"); 228 Serial.print(utc.minute); 229 Serial.print(":"); 230 Serial.print(utc.second); 231 Serial.println(); 232 Serial.println((char)lat.latDirection); 233 Serial.println((char)lon.lonDirection); 234 235 // Serial.print("lat DDMM.MMMMM = "); 236 // Serial.println(lat.latitude, 5); 237 // Serial.print(" lon DDDMM.MMMMM = "); 238 // Serial.println(lon.lonitude, 5); 239 Serial.print("lat degree = "); 240 Serial.println(lat.latitudeDegree,6); 241 Serial.print("lon degree = "); 242 Serial.println(lon.lonitudeDegree,6); 243 244 Serial.print("star userd = "); 245 Serial.println(starUserd); 246 Serial.print("alt high = "); 247 Serial.println(high); 248 Serial.print("sog = "); 249 Serial.println(sog); 250 Serial.print("cog = "); 251 Serial.println(cog); 252 Serial.print("gnss mode = "); 253 Serial.println(gnss.getGnssMode()); 254 delay(6000); 255 256 257//-------------------------------------------------------------------------------------------------------------------------------- 258 259 260 sBmm150MagData_t magData = bmm150.getGeomagneticData(); 261 Serial.print("mag x = "); Serial.print(magData.x); Serial.println(" uT"); 262 Serial.print("mag y = "); Serial.print(magData.y); Serial.println(" uT"); 263 Serial.print("mag z = "); Serial.print(magData.z); Serial.println(" uT"); 264 float compassDegree = bmm150.getCompassDegree(); 265 Serial.print("the angle between the pointing direction and north (counterclockwise) is:"); 266 Serial.println(compassDegree); 267 Serial.println("--------------------------------"); 268 delay(6000); 269 270 271//--------------------------------------------------------------------------------------------------------------------------------- 272 273 274 if (readStep){ 275 uint16_t stepCounter = 0; 276 //read step counter from hardware bmi160 277 if (bmi160.readStepCounter(&stepCounter)==BMI160_OK){ 278 Serial.print("step counter = ");Serial.println(stepCounter); 279 } 280 readStep = false; 281 } 282}
Downloadable files
Schematics
The schematis of the boards
https://drive.google.com/drive/folders/1lfeFtXaTV4sMYiCDdATukX4XpHF--0Ba?usp=sharing
HC1
Mission Overview
HC1 Mission Overview.pdf
Comments
Only logged in users can leave comments