Skip to content

Commit 96ee3a0

Browse files
committed
Add Qwiic bus power control and speed control
1 parent 2701a62 commit 96ee3a0

File tree

8 files changed

+98
-19
lines changed

8 files changed

+98
-19
lines changed

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ Change Log
44
v1.1
55
---------
66

7-
* Added support for exFat microSD cards. Tested up to 512GB. We still suppport smaller FAT16 and FAT32 formatted cards.
7+
* Add support for exFat microSD cards. Tested up to 512GB. Smaller FAT16 and FAT32 formatted cards are still supported.
8+
* Add support for MS8607 PHT sensor
9+
* Add ability to turn on/off power on Qwiic bus when time between sensor readings is > 2s. By default the bus powers down to save power but there may be instances where user wants to keep sensors powered up and running between reads. This can be accessed via the Attached Devices menu.
10+
* Add ability to limit I2C bus speed. Most devices operate at 400kHz I2C. Some (MCP9600) are automatically limited by OLA to 100kHz. There may be instances, because of bus length or other, where the user may want to artifically limit the bus speed. This can be access via the Attached Devices menu.
11+
812

913
v1.0
1014
---------
11-
Initial release. Support for
12-
13-
*
15+
Initial release.

Firmware/OpenLog_Artemis/Sensors.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,5 +716,9 @@ void determineMaxI2CSpeed()
716716
else if (settings.sensor_uBlox.i2cSpeed == 100000)
717717
maxSpeed = 100000;
718718

719+
//If user wants to limit the I2C bus speed, do it here
720+
if(maxSpeed > settings.qwiicBusMaxSpeed)
721+
maxSpeed = settings.qwiicBusMaxSpeed;
722+
719723
qwiic.setClock(maxSpeed);
720724
}

Firmware/OpenLog_Artemis/lowerPower.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,15 @@ void goToSleep()
114114
am_hal_gpio_pinconfig(x, g_AM_HAL_GPIO_DISABLE);
115115

116116
//We can't leave these power control pins floating
117-
qwiicPowerOff();
118117
imuPowerOff();
119118
microSDPowerOff();
120119

120+
//Keep Qwiic bus powered on if user desires it
121+
if (settings.powerDownQwiicBusBetweenReads == true)
122+
qwiicPowerOff();
123+
else
124+
qwiicPowerOn(); //Make sure pins stays as output
125+
121126
//Power down Flash, SRAM, cache
122127
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_CACHE); //Turn off CACHE
123128
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_FLASH_512K); //Turn off everything but lower 512k

Firmware/OpenLog_Artemis/menuAttachedDevices.ino

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ void menuAttachedDevices()
2626

2727
//See what's on the I2C bus. Will set the qwiicAvailable bools.
2828
if (detectQwiicDevices() == false)
29-
{
30-
Serial.println("No devices detected on Qwiic bus");
31-
delay(3000);
32-
return;
33-
}
29+
Serial.println("**No devices detected on Qwiic bus**");
3430

3531
//Create array of pointers to the configure functions
3632
typedef void(*FunctionPointer)();
@@ -109,6 +105,9 @@ void menuAttachedDevices()
109105
Serial.printf("%d) MS8607 Pressure Humidity Temperature Sensor\n", availableDevices++);
110106
}
111107

108+
functionPointers[availableDevices - 1] = menuConfigure_QwiicBus;
109+
Serial.printf("%d) Configure Qwiic Settings\n", availableDevices++);
110+
112111
Serial.println("x) Exit");
113112

114113
byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds
@@ -262,6 +261,46 @@ bool testDevice(uint8_t i2cAddress)
262261
return true;
263262
}
264263

264+
void menuConfigure_QwiicBus()
265+
{
266+
while (1)
267+
{
268+
Serial.println();
269+
Serial.println("Menu: Configure Qwiic Bus");
270+
271+
Serial.print("1) If sensor read time is greater than 2s, turn off bus power: ");
272+
if (settings.powerDownQwiicBusBetweenReads == true) Serial.println("Enabled");
273+
else Serial.println("Disabled");
274+
275+
Serial.print("2) Set Max Qwiic Bus Speed: ");
276+
Serial.println(settings.qwiicBusMaxSpeed);
277+
278+
Serial.println("x) Exit");
279+
280+
byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds
281+
282+
if (incoming == '1')
283+
settings.powerDownQwiicBusBetweenReads ^= 1;
284+
else if (incoming == '2')
285+
{
286+
Serial.print("Enter max frequency to run Qwiic bus: (100000 to 400000): ");
287+
int amt = getNumber(menuTimeout);
288+
if (amt >= 100000 && amt <= 400000)
289+
settings.qwiicBusMaxSpeed = amt;
290+
else
291+
Serial.println("Error: Out of range");
292+
}
293+
else if (incoming == 'x')
294+
break;
295+
else if (incoming == STATUS_GETBYTE_TIMEOUT)
296+
break;
297+
else
298+
printUnknown(incoming);
299+
}
300+
301+
qwiicOnline.LPS25HB = false; //Mark as offline so it will be started with new settings
302+
}
303+
265304
void menuConfigure_LPS25HB()
266305
{
267306
while (1)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
void menuDebug()
2+
{
3+
while (1)
4+
{
5+
Serial.println();
6+
Serial.println("Menu: Configure Debug Settings");
7+
8+
Serial.print("1) Debug Messages: ");
9+
if (settings.printDebugMessages == true) Serial.println("Enabled");
10+
else Serial.println("Disabled");
11+
12+
Serial.println("x) Exit");
13+
14+
byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds
15+
16+
if (incoming == '1')
17+
{
18+
settings.printDebugMessages ^= 1;
19+
}
20+
else if (incoming == 'x')
21+
break;
22+
else if (incoming == STATUS_GETBYTE_TIMEOUT)
23+
break;
24+
else
25+
printUnknown(incoming);
26+
}
27+
}

Firmware/OpenLog_Artemis/menuMain.ino

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ void menuMain()
2323

2424
Serial.println("6) Detect / Configure Attached Devices");
2525

26-
//Serial.println(") Configure Battery Voltage Logging");
27-
//Enable VCC logging
28-
2926
Serial.println("r) Reset all settings to default");
3027

28+
//Serial.println("d) Debug Menu");
29+
3130
Serial.println("x) Return to logging");
3231

3332
byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds
@@ -45,12 +44,7 @@ void menuMain()
4544
else if (incoming == '6')
4645
menuAttachedDevices();
4746
else if (incoming == 'd')
48-
{
49-
Serial.print("Debug Messages ");
50-
settings.printDebugMessages ^= 1;
51-
if(settings.printDebugMessages == true) Serial.println("Enabled");
52-
else Serial.println("Disabled");
53-
}
47+
menuDebug();
5448
else if (incoming == 'r')
5549
{
5650
Serial.println("\n\rResetting to factory defaults. Continue? Press 'y':");

Firmware/OpenLog_Artemis/nvm.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ void recordSettingsToFile()
9090
settingsFile.println("logAnalogVoltages=" + (String)settings.logAnalogVoltages);
9191
settingsFile.println("localUTCOffset=" + (String)settings.localUTCOffset);
9292
settingsFile.println("printDebugMessages=" + (String)settings.printDebugMessages);
93+
settingsFile.println("powerDownQwiicBusBetweenReads=" + (String)settings.powerDownQwiicBusBetweenReads);
94+
settingsFile.println("qwiicBusMaxSpeed=" + (String)settings.qwiicBusMaxSpeed);
9395
// settingsFile.println("=" + (String)settings.sensor_LPS25HB.);
9496

9597
settingsFile.close();
@@ -278,6 +280,10 @@ bool parseLine(char* str) {
278280
settings.localUTCOffset = d;
279281
else if (strcmp(settingName, "printDebugMessages") == 0)
280282
settings.printDebugMessages = d;
283+
else if (strcmp(settingName, "powerDownQwiicBusBetweenReads") == 0)
284+
settings.powerDownQwiicBusBetweenReads = d;
285+
else if (strcmp(settingName, "qwiicBusMaxSpeed") == 0)
286+
settings.qwiicBusMaxSpeed = d;
281287
// else if (strcmp(settingName, "") == 0)
282288
// settings. = d;
283289
else

Firmware/OpenLog_Artemis/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ struct struct_settings {
169169
bool logAnalogVoltages = true;
170170
int localUTCOffset = -7; //Default to Denver because we can
171171
bool printDebugMessages = false;
172+
bool powerDownQwiicBusBetweenReads = true;
173+
int qwiicBusMaxSpeed = 400000;
172174
struct_LPS25HB sensor_LPS25HB;
173175
struct_uBlox sensor_uBlox;
174176
struct_VL53L1X sensor_VL53L1X;

0 commit comments

Comments
 (0)