-
Notifications
You must be signed in to change notification settings - Fork 19
New combined demo showing most non I2C input sensors. #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cac3172
New combined demo showing most non I2C input sensors.
marcmerlin 5e1fccb
Added I2C scanner for debug.
marcmerlin cb7fbd7
Added I2C scanner for debug + fixed diplay offset + add tone.
marcmerlin 687d40b
Added I2C scanner for debug + fixed diplay offset + add tone.
marcmerlin b32d82b
Added code to show pressure and accelerometer
marcmerlin ec8fe6c
Work around I2c hang by spacing out reads to different devices.
marcmerlin 0c4797d
Re-enable I2C scan, it works without killing the OLED screen.
marcmerlin a135ba8
Update Combined_Demo.ino
marqdevx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Combined Demo by Marc MERLIN <marc_soft@merlins.org> | ||
|
||
#include "Arduino_SensorKit.h" | ||
|
||
uint8_t button = 4; | ||
uint8_t led = 6; | ||
uint8_t pot = A0; | ||
uint8_t mic = A2; | ||
uint8_t light = A3; | ||
|
||
// From https://playground.arduino.cc/Main/I2cScanner/ | ||
// learn more about I2C here | ||
// https://www.seeedstudio.com/blog/2019/09/25/uart-vs-i2c-vs-spi-communication-protocols-and-uses/ | ||
// Scanner from https://github.com/RobTillaart/Arduino/blob/master/sketches/MultiSpeedI2CScanner/MultiSpeedI2CScanner.ino | ||
// 30038 25 0x19 V V V V V V V V | ||
// 30133 60 0x3C V V V V V V V V | ||
// 30296 119 0x77 V V V V V V V V | ||
void i2c_scan() { | ||
uint8_t error, address, nDevices; | ||
|
||
Wire.begin(); | ||
Serial.println("Scanning..."); | ||
|
||
nDevices = 0; | ||
for(address = 1; address < 127; address++ ) | ||
{ | ||
//Serial.println("I2C scan"); | ||
// The i2c_scanner uses the return value of | ||
// the Write.endTransmisstion to see if | ||
// a device did acknowledge to the address. | ||
Wire.beginTransmission(address); | ||
error = Wire.endTransmission(); | ||
|
||
if (error == 0) | ||
{ | ||
Serial.print("I2C device found at address 0x"); | ||
if (address<16) | ||
Serial.print("0"); | ||
Serial.print(address,HEX); | ||
Serial.println(" !"); | ||
|
||
nDevices++; | ||
} | ||
else if (error==4) | ||
{ | ||
Serial.print("Unknown error at address 0x"); | ||
if (address<16) | ||
Serial.print("0"); | ||
Serial.println(address,HEX); | ||
} | ||
} | ||
if (nDevices == 0) | ||
Serial.println("No I2C devices found\n"); | ||
else | ||
Serial.println("done\n"); | ||
} | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
// Running scan stops the OLED from working | ||
//i2c_scan(); | ||
|
||
pinMode(mic , INPUT); | ||
pinMode(light , INPUT); | ||
|
||
pinMode(button , INPUT); | ||
pinMode(led, OUTPUT); | ||
digitalWrite(led, LOW); | ||
|
||
Environment.begin(); | ||
|
||
Oled.begin(); | ||
Oled.setFlipMode(true); | ||
|
||
// Enabling any of those 2 stops the OLED from working | ||
//Accelerometer.begin(); | ||
//Pressure.begin(); | ||
} | ||
|
||
void loop() { | ||
|
||
Oled.setFont(u8x8_font_amstrad_cpc_extended_r); | ||
|
||
#if 0 | ||
Oled.setCursor(0, 0); | ||
Oled.print("x:"); | ||
Oled.print(Accelerometer.readX()); | ||
Oled.print(" "); | ||
Oled.print("y:"); | ||
Oled.print(Accelerometer.readY()); | ||
Oled.print(" "); | ||
Oled.print("z:"); | ||
Oled.print(Accelerometer.readZ()); | ||
// Similar problem with pressure sensor | ||
Oled.print(Pressure.readAltitude()); | ||
#endif | ||
|
||
Oled.setCursor(0, 0); | ||
Oled.print("But:"); | ||
if (digitalRead(button)) { | ||
digitalWrite(led, HIGH); | ||
Oled.print("1"); | ||
} else { | ||
digitalWrite(led, LOW); | ||
Oled.print("0"); | ||
} | ||
|
||
// https://github.com/olikraus/u8g2/wiki/u8x8reference#print | ||
// looks like we need an offset of 9 for a font of 8 | ||
// if the offset is wrong, the text gets displayed on | ||
// the wrong line | ||
uint16_t pot_value = analogRead(pot); | ||
Oled.setCursor(0, 9); | ||
Oled.print("Pot: "); | ||
Oled.print(pot_value); | ||
Oled.print(" "); | ||
|
||
uint16_t mic_value = analogRead(mic); | ||
Oled.setCursor(0, 18); | ||
Oled.print("Mic: "); | ||
Oled.print(mic_value); | ||
Oled.print(" "); | ||
|
||
uint16_t light_value = analogRead(light); | ||
Oled.setCursor(0, 27); | ||
Oled.print("Light: "); | ||
Oled.print(light_value); | ||
Oled.print(" "); | ||
|
||
Oled.setCursor(0, 45); | ||
Oled.print("Temp:"); | ||
Oled.print(Environment.readTemperature()); | ||
Oled.print("C"); | ||
|
||
Oled.setCursor(0, 54); | ||
Oled.print("Hum: "); | ||
Oled.print(Environment.readHumidity()); | ||
Oled.print("%"); | ||
|
||
Oled.refreshDisplay(); | ||
delay(100); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marqdevx enabling any of those 2 lines with library 1.0.5, stops the OLED from working.