Skip to content

Commit c6b0ca9

Browse files
authored
Merge pull request #95 from sparkfun/release_candidate_v2
v2.0
2 parents d8a0db5 + c7dd641 commit c6b0ca9

25 files changed

+1597
-692
lines changed
-237 KB
Binary file not shown.
351 KB
Binary file not shown.
350 KB
Binary file not shown.

Firmware/OpenLog_Artemis/OpenLog_Artemis.ino

Lines changed: 183 additions & 89 deletions
Large diffs are not rendered by default.

Firmware/OpenLog_Artemis/Sensors.ino

Lines changed: 258 additions & 136 deletions
Large diffs are not rendered by default.

Firmware/OpenLog_Artemis/autoDetect.ino

Lines changed: 71 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ bool addDevice(deviceType_e deviceType, uint8_t address, uint8_t muxAddress, uin
255255
temp->configPtr = new struct_MS5837;
256256
}
257257
break;
258-
// case DEVICE_QWIIC_BUTTON:
259-
// {
260-
// temp->classPtr = new QwiicButton;
261-
// temp->configPtr = new struct_QWIIC_BUTTON;
262-
// }
263-
// break;
258+
case DEVICE_QWIIC_BUTTON:
259+
{
260+
temp->classPtr = new QwiicButton;
261+
temp->configPtr = new struct_QWIIC_BUTTON;
262+
}
263+
break;
264264
case DEVICE_BIO_SENSOR_HUB:
265265
{
266266
temp->classPtr = new SparkFun_Bio_Sensor_Hub(32, 11, address); // Reset pin is 32, MFIO pin is 11
@@ -295,7 +295,7 @@ bool beginQwiicDevices()
295295
bool everythingStarted = true;
296296

297297
waitForQwiicBusPowerDelay(); // Wait while the qwiic devices power up - if required
298-
298+
299299
qwiicPowerOnDelayMillis = settings.qwiicBusPowerUpDelayMs; // Set qwiicPowerOnDelayMillis to the _minimum_ defined by settings.qwiicBusPowerUpDelayMs. It will be increased if required.
300300

301301
int numberOfSCD30s = 0; // Keep track of how many SCD30s we begin so we can delay before starting the second and subsequent ones
@@ -312,13 +312,13 @@ bool beginQwiicDevices()
312312
while (temp != NULL)
313313
{
314314
openConnection(temp->muxAddress, temp->portNumber); //Connect to this device through muxes as needed
315-
315+
316316
if (settings.printDebugMessages == true)
317317
{
318318
SerialPrintf2("beginQwiicDevices: attempting to begin deviceType %s", getDeviceName(temp->deviceType));
319319
SerialPrintf4(" at address 0x%02X using mux address 0x%02X and port number %d\r\n", temp->address, temp->muxAddress, temp->portNumber);
320320
}
321-
321+
322322
//Attempt to begin the device
323323
switch (temp->deviceType)
324324
{
@@ -349,12 +349,13 @@ bool beginQwiicDevices()
349349
break;
350350
case DEVICE_GPS_UBLOX:
351351
{
352-
qwiic.setPullups(0); //Disable pullups for u-blox comms.
352+
setQwiicPullups(0); //Disable pullups for u-blox comms.
353353
SFE_UBLOX_GNSS *tempDevice = (SFE_UBLOX_GNSS *)temp->classPtr;
354354
struct_uBlox *nodeSetting = (struct_uBlox *)temp->configPtr; //Create a local pointer that points to same spot as node does
355355
if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required
356+
if(settings.printGNSSDebugMessages == true) tempDevice->enableDebugging(); // Enable debug messages if required
356357
temp->online = tempDevice->begin(qwiic, temp->address); //Wire port, Address
357-
qwiic.setPullups(settings.qwiicBusPullUps); //Re-enable pullups.
358+
setQwiicPullups(settings.qwiicBusPullUps); //Re-enable pullups.
358359
}
359360
break;
360361
case DEVICE_PROXIMITY_VCNL4040:
@@ -527,15 +528,15 @@ bool beginQwiicDevices()
527528
temp->online = true;
528529
}
529530
break;
530-
// case DEVICE_QWIIC_BUTTON:
531-
// {
532-
// QwiicButton *tempDevice = (QwiicButton *)temp->classPtr;
533-
// struct_QWIIC_BUTTON *nodeSetting = (struct_QWIIC_BUTTON *)temp->configPtr; //Create a local pointer that points to same spot as node does
534-
// if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required
535-
// if (tempDevice->begin(temp->address, qwiic) == true) //Address, Wire port. Returns true on success.
536-
// temp->online = true;
537-
// }
538-
// break;
531+
case DEVICE_QWIIC_BUTTON:
532+
{
533+
QwiicButton *tempDevice = (QwiicButton *)temp->classPtr;
534+
struct_QWIIC_BUTTON *nodeSetting = (struct_QWIIC_BUTTON *)temp->configPtr; //Create a local pointer that points to same spot as node does
535+
if (nodeSetting->powerOnDelayMillis > qwiicPowerOnDelayMillis) qwiicPowerOnDelayMillis = nodeSetting->powerOnDelayMillis; // Increase qwiicPowerOnDelayMillis if required
536+
if (tempDevice->begin(temp->address, qwiic) == true) //Address, Wire port. Returns true on success.
537+
temp->online = true;
538+
}
539+
break;
539540
case DEVICE_BIO_SENSOR_HUB:
540541
{
541542
SparkFun_Bio_Sensor_Hub *tempDevice = (SparkFun_Bio_Sensor_Hub *)temp->classPtr;
@@ -657,7 +658,7 @@ void configureDevice(node * temp)
657658
break;
658659
case DEVICE_GPS_UBLOX:
659660
{
660-
qwiic.setPullups(0); //Disable pullups for u-blox comms.
661+
setQwiicPullups(0); //Disable pullups for u-blox comms.
661662

662663
SFE_UBLOX_GNSS *sensor = (SFE_UBLOX_GNSS *)temp->classPtr;
663664
struct_uBlox *nodeSetting = (struct_uBlox *)temp->configPtr;
@@ -667,7 +668,7 @@ void configureDevice(node * temp)
667668
sensor->saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the current ioPortsettings to flash and BBR
668669

669670
sensor->setAutoPVT(nodeSetting->useAutoPVT); // Use autoPVT as required
670-
671+
671672
if (1000000ULL / settings.usBetweenReadings <= 1) //If we are slower than 1Hz logging rate
672673
// setNavigationFrequency expects a uint8_t to define the number of updates per second
673674
// So the slowest rate we can set with setNavigationFrequency is 1Hz
@@ -678,7 +679,7 @@ void configureDevice(node * temp)
678679
else
679680
sensor->setNavigationFrequency(10); //Set nav freq to 10Hz. Max output depends on the module used.
680681

681-
qwiic.setPullups(settings.qwiicBusPullUps); //Re-enable pullups.
682+
setQwiicPullups(settings.qwiicBusPullUps); //Re-enable pullups.
682683
}
683684
break;
684685
case DEVICE_PROXIMITY_VCNL4040:
@@ -818,17 +819,17 @@ void configureDevice(node * temp)
818819
sensor->setFluidDensity(sensorSetting->fluidDensity);
819820
}
820821
break;
821-
// case DEVICE_QWIIC_BUTTON:
822-
// {
823-
// QwiicButton *sensor = (QwiicButton *)temp->classPtr;
824-
// struct_QWIIC_BUTTON *sensorSetting = (struct_QWIIC_BUTTON *)temp->configPtr;
825-
//
826-
// if (sensorSetting->ledState)
827-
// sensor->LEDon(sensorSetting->ledBrightness);
828-
// else
829-
// sensor->LEDoff();
830-
// }
831-
// break
822+
case DEVICE_QWIIC_BUTTON:
823+
{
824+
QwiicButton *sensor = (QwiicButton *)temp->classPtr;
825+
struct_QWIIC_BUTTON *sensorSetting = (struct_QWIIC_BUTTON *)temp->configPtr;
826+
827+
if (sensorSetting->ledState)
828+
sensor->LEDon(sensorSetting->ledBrightness);
829+
else
830+
sensor->LEDoff();
831+
}
832+
break;
832833
case DEVICE_BIO_SENSOR_HUB:
833834
{
834835
SparkFun_Bio_Sensor_Hub *sensor = (SparkFun_Bio_Sensor_Hub *)temp->classPtr;
@@ -854,6 +855,10 @@ void configureQwiicDevices()
854855
configureDevice(temp);
855856
temp = temp->next;
856857
}
858+
859+
//Now that the settings are loaded and the devices are configured,
860+
//try for 400kHz but reduce to 100kHz if certain devices are attached
861+
setMaxI2CSpeed();
857862
}
858863

859864
//Returns a pointer to the menu function that configures this particular device type
@@ -936,9 +941,9 @@ FunctionPointer getConfigFunctionPtr(uint8_t nodeNumber)
936941
case DEVICE_PRESSURE_MS5837:
937942
ptr = (FunctionPointer)menuConfigure_MS5837;
938943
break;
939-
// case DEVICE_QWIIC_BUTTON:
940-
// ptr = (FunctionPointer)menuConfigure_QWIIC_BUTTON;
941-
// break;
944+
case DEVICE_QWIIC_BUTTON:
945+
ptr = (FunctionPointer)menuConfigure_QWIIC_BUTTON;
946+
break;
942947
case DEVICE_BIO_SENSOR_HUB:
943948
ptr = (FunctionPointer)menuConfigure_BIO_SENSOR_HUB;
944949
break;
@@ -1088,7 +1093,7 @@ void swap(struct node * a, struct node * b)
10881093
#define ADR_VCNL4040 0x60
10891094
#define ADR_SCD30 0x61
10901095
#define ADR_MCP9600 0x60 //0x60 to 0x67
1091-
//#define ADR_QWIIC_BUTTON 0x6F //But can be any address... Limit the range to 0x68-0x6F
1096+
#define ADR_QWIIC_BUTTON 0x6F //But can be any address... Limit the range to 0x68-0x6F
10921097
#define ADR_MULTIPLEXER 0x70 //0x70 to 0x77
10931098
#define ADR_SHTC3 0x70
10941099
#define ADR_MS5637 0x76
@@ -1204,15 +1209,15 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
12041209
case 0x42:
12051210
{
12061211
//Confidence: High - Sends/receives CRC checked data response
1207-
qwiic.setPullups(0); //Disable pullups to minimize CRC issues
1212+
setQwiicPullups(0); //Disable pullups to minimize CRC issues
12081213
SFE_UBLOX_GNSS sensor;
1209-
if(settings.printDebugMessages == true) sensor.enableDebugging(); // Enable debug messages if required
1214+
if(settings.printGNSSDebugMessages == true) sensor.enableDebugging(); // Enable debug messages if required
12101215
if (sensor.begin(qwiic, i2cAddress) == true) //Wire port, address
12111216
{
1212-
qwiic.setPullups(settings.qwiicBusPullUps); //Re-enable pullups to prevent ghosts at 0x43 onwards
1217+
setQwiicPullups(settings.qwiicBusPullUps); //Re-enable pullups to prevent ghosts at 0x43 onwards
12131218
return (DEVICE_GPS_UBLOX);
12141219
}
1215-
qwiic.setPullups(settings.qwiicBusPullUps); //Re-enable pullups for normal discovery
1220+
setQwiicPullups(settings.qwiicBusPullUps); //Re-enable pullups for normal discovery
12161221
}
12171222
break;
12181223
case 0x44:
@@ -1380,20 +1385,20 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
13801385
return (DEVICE_TEMPERATURE_MCP9600);
13811386
}
13821387
break;
1383-
// case 0x68:
1384-
// case 0x69:
1385-
// case 0x6A:
1386-
// case 0x6B:
1387-
// case 0x6C:
1388-
// case 0x6D:
1389-
// case 0x6E:
1390-
// case 0x6F:
1391-
// {
1392-
// QwiicButton sensor;
1393-
// if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
1394-
// return (DEVICE_QWIIC_BUTTON);
1395-
// }
1396-
// break;
1388+
case 0x68:
1389+
case 0x69:
1390+
case 0x6A:
1391+
case 0x6B:
1392+
case 0x6C:
1393+
case 0x6D:
1394+
case 0x6E:
1395+
case 0x6F:
1396+
{
1397+
QwiicButton sensor;
1398+
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
1399+
return (DEVICE_QWIIC_BUTTON);
1400+
}
1401+
break;
13971402
case 0x70:
13981403
{
13991404
//Ignore devices we've already recorded. This was causing the mux to get tested, a begin() would happen, and the mux would be reset.
@@ -1445,7 +1450,7 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
14451450
if (sensor2.begin(qwiic) == true) //Wire port
14461451
{
14471452
if (sensor2.getModel() <= 1) // Check that getModel returns 0 or 1. It will (hopefully) return 255 if an MS5637 is attached.
1448-
return (DEVICE_PRESSURE_MS5837);
1453+
return (DEVICE_PRESSURE_MS5837);
14491454
}
14501455

14511456
//Confidence: High - does CRC on internal EEPROM read - but do this second as a MS5837 will appear as a MS5637
@@ -1469,7 +1474,7 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
14691474
{
14701475
//Ignore devices we've already recorded. This was causing the mux to get tested, a begin() would happen, and the mux would be reset.
14711476
if (deviceExists(DEVICE_MULTIPLEXER, i2cAddress, muxAddress, portNumber) == true) return (DEVICE_MULTIPLEXER);
1472-
1477+
14731478
BME280 sensor;
14741479
sensor.setI2CAddress(i2cAddress);
14751480
if (sensor.beginI2C(qwiic) == true) //Wire port
@@ -1510,7 +1515,7 @@ deviceType_e testMuxDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portN
15101515
{
15111516
//Ignore devices we've already recorded. This was causing the mux to get tested, a begin() would happen, and the mux would be reset.
15121517
if (deviceExists(DEVICE_MULTIPLEXER, i2cAddress, muxAddress, portNumber) == true) return (DEVICE_MULTIPLEXER);
1513-
1518+
15141519
//Confidence: Medium - Write/Read/Clear to 0x00
15151520
if (multiplexerBegin(i2cAddress, qwiic) == true) //Address, Wire port
15161521
return (DEVICE_MULTIPLEXER);
@@ -1521,7 +1526,7 @@ deviceType_e testMuxDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portN
15211526
//Ignore devices we've already recorded. This was causing the mux to get tested, a begin() would happen, and the mux would be reset.
15221527
if (deviceExists(DEVICE_MULTIPLEXER, i2cAddress, muxAddress, portNumber) == true) return (DEVICE_MULTIPLEXER);
15231528

1524-
// If an MS8607 is connected, multiplexerBegin causes the MS8607 to 'crash' and lock up the I2C bus... So we need to check if an MS8607 is connected first.
1529+
// If an MS8607 is connected, multiplexerBegin causes the MS8607 to 'crash' and lock up the I2C bus... So we need to check if an MS8607 is connected first.
15251530
// We will use the MS5637 as this will test for itself, the MS5837 and the pressure sensor of the MS8607
15261531
// Just to make life even more complicated, a mux with address 0x76 will also appear as an MS5637 due to the way the MS5637 eeprom crc check is calculated.
15271532
// So, we can't use .begin as the test for a MS5637 / MS5837 / MS8607. We need to be more creative!
@@ -1530,7 +1535,7 @@ deviceType_e testMuxDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portN
15301535
// An MS5637 / MS5837 / MS8607 will return the value stored in its eeprom which _hopefully_ is not 0xA0A0!
15311536

15321537
// Let's hope this doesn't cause problems for the BME280...! We should be OK as the default address for the BME280 is 0x77.
1533-
1538+
15341539
qwiic.beginTransmission((uint8_t)i2cAddress);
15351540
qwiic.write((uint8_t)0xA0);
15361541
uint8_t i2c_status = qwiic.endTransmission();
@@ -1558,7 +1563,7 @@ deviceType_e testMuxDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portN
15581563
{
15591564
//Ignore devices we've already recorded. This was causing the mux to get tested, a begin() would happen, and the mux would be reset.
15601565
if (deviceExists(DEVICE_MULTIPLEXER, i2cAddress, muxAddress, portNumber) == true) return (DEVICE_MULTIPLEXER);
1561-
1566+
15621567
//Confidence: Medium - Write/Read/Clear to 0x00
15631568
if (multiplexerBegin(i2cAddress, qwiic) == true) //Address, Wire port
15641569
return (DEVICE_MULTIPLEXER);
@@ -1614,7 +1619,7 @@ bool setMuxPortState(uint8_t portBits, uint8_t deviceAddress, TwoWire &wirePort,
16141619
wirePort.beginTransmission(deviceAddress);
16151620
for (int i = 0; i < extraBytes; i++)
16161621
{
1617-
wirePort.write(0x00); // Writing these extra bytes seems key to avoiding the slippery mux problem
1622+
wirePort.write((uint8_t)0x00); // Writing these extra bytes seems key to avoiding the slippery mux problem
16181623
}
16191624
wirePort.write(portBits);
16201625
if (wirePort.endTransmission() != 0)
@@ -1706,9 +1711,9 @@ const char* getDeviceName(deviceType_e deviceNumber)
17061711
case DEVICE_PRESSURE_MS5837:
17071712
return "Pressure-MS5837";
17081713
break;
1709-
// case DEVICE_QWIIC_BUTTON:
1710-
// return "Qwiic_Button";
1711-
// break;
1714+
case DEVICE_QWIIC_BUTTON:
1715+
return "Qwiic_Button";
1716+
break;
17121717
case DEVICE_BIO_SENSOR_HUB:
17131718
return "Bio-Sensor-Oximeter";
17141719
break;

Firmware/OpenLog_Artemis/logging.ino

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@ char* findNextAvailableLog(int &newFileNumber, const char *fileLeader)
2626
static char newFileName[40];
2727
while (1)
2828
{
29-
sprintf(newFileName, "%s%05u.TXT", fileLeader, newFileNumber); //Splice the new file number into this file name. Max no. is 99999.
29+
char newFileNumberStr[6];
30+
if (newFileNumber < 10)
31+
sprintf(newFileNumberStr, "0000%d", newFileNumber);
32+
else if (newFileNumber < 100)
33+
sprintf(newFileNumberStr, "000%d", newFileNumber);
34+
else if (newFileNumber < 1000)
35+
sprintf(newFileNumberStr, "00%d", newFileNumber);
36+
else if (newFileNumber < 10000)
37+
sprintf(newFileNumberStr, "0%d", newFileNumber);
38+
else
39+
sprintf(newFileNumberStr, "%d", newFileNumber);
40+
sprintf(newFileName, "%s%s.TXT", fileLeader, newFileNumberStr); //Splice the new file number into this file name. Max no. is 99999.
3041

3142
if (sd.exists(newFileName) == false) break; //File name not found so we will use it.
3243

0 commit comments

Comments
 (0)