Last active
February 24, 2026 03:12
-
-
Save ksasao/08efebfce69c22da6bcc8e698d1c73c5 to your computer and use it in GitHub Desktop.
Seeed Studio の半導体ガスセンサ11種類の出力をI2Cに接続するサンプル。Adafruit_ADS1115はADDRピンの接続先を変更することで最大4種類のI2Cアドレスを設定することができます。
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
| #include "M5Atom.h" | |
| #include <Adafruit_ADS1X15.h> | |
| Adafruit_ADS1115 ads, ads2, ads3; | |
| uint8_t | |
| DisBuff[2 + 5 * 5 * 3]; | |
| void setBuff(uint8_t Rdata, uint8_t Gdata, | |
| uint8_t Bdata) { | |
| DisBuff[0] = 0x05; | |
| DisBuff[1] = 0x05; | |
| for (int i = 0; i < 25; i++) { | |
| DisBuff[2 + i * 3 + 0] = Rdata; | |
| DisBuff[2 + i * 3 + 1] = Gdata; | |
| DisBuff[2 + i * 3 + 2] = Bdata; | |
| } | |
| } | |
| bool i2cActive(int8_t address) { | |
| Wire.beginTransmission(address); | |
| int error = Wire.endTransmission(); | |
| Serial.print("I2C "); | |
| Serial.print(address, HEX); | |
| if (error == 0) { | |
| Serial.println(" found."); | |
| return true; | |
| } | |
| Serial.println(" not found."); | |
| return false; | |
| } | |
| void setup() { | |
| M5.begin(true, false, true); | |
| Serial.begin(115200); | |
| delay(10); | |
| setBuff(0xff, 0x00, 0x00); | |
| M5.dis.displaybuff( | |
| DisBuff); | |
| Wire.begin(26, 32); | |
| delay(500); | |
| Serial.println("M5Atom I2C Tester"); | |
| i2cActive(0x48); | |
| if (!ads.begin(0x48, &Wire)) { | |
| Serial.println("Failed to initialize ADS."); | |
| while (1) { | |
| delay(100); | |
| } | |
| } | |
| i2cActive(0x49); | |
| if (!ads2.begin(0x49, &Wire)) { | |
| Serial.println("Failed to initialize ADS."); | |
| while (1) { | |
| delay(100); | |
| } | |
| } | |
| i2cActive(0x4A); | |
| if (!ads3.begin(0x4A, &Wire)) { | |
| Serial.println("Failed to initialize ADS."); | |
| while (1) { | |
| delay(100); | |
| } | |
| } | |
| } | |
| uint8_t FSM = 0; | |
| void loop() { | |
| if (M5.Btn | |
| .wasPressed()) { | |
| switch (FSM) { | |
| case 0: | |
| setBuff(0x40, 0x00, 0x00); | |
| break; | |
| case 1: | |
| setBuff(0x00, 0x40, 0x00); | |
| break; | |
| case 2: | |
| setBuff(0x00, 0x00, 0x40); | |
| break; | |
| case 3: | |
| setBuff(0x20, 0x20, 0x20); | |
| break; | |
| default: | |
| break; | |
| } | |
| M5.dis.displaybuff(DisBuff); | |
| FSM++; | |
| if (FSM >= 4) { | |
| FSM = 0; | |
| } | |
| } | |
| delay(50); | |
| int16_t adc0, adc1, adc2, adc3; | |
| int16_t adc4, adc5, adc6, adc7; | |
| int16_t adc8, adc9, adc10; | |
| float volts0, volts1, volts2, volts3; | |
| adc0 = ads.readADC_SingleEnded(0); | |
| adc1 = ads.readADC_SingleEnded(1); | |
| adc2 = ads.readADC_SingleEnded(2); | |
| adc3 = ads.readADC_SingleEnded(3); | |
| adc4 = ads2.readADC_SingleEnded(0); | |
| adc5 = ads2.readADC_SingleEnded(1); | |
| adc6 = ads2.readADC_SingleEnded(2); | |
| adc7 = ads2.readADC_SingleEnded(3); | |
| adc8 = ads3.readADC_SingleEnded(0); | |
| adc9 = ads3.readADC_SingleEnded(1); | |
| adc10 = ads3.readADC_SingleEnded(2); | |
| Serial.print(adc0); | |
| Serial.print(","); | |
| Serial.print(adc1); | |
| Serial.print(","); | |
| Serial.print(adc2); | |
| Serial.print(","); | |
| Serial.print(adc3); | |
| Serial.print(","); | |
| Serial.print(adc4); | |
| Serial.print(","); | |
| Serial.print(adc5); | |
| Serial.print(","); | |
| Serial.print(adc6); | |
| Serial.print(","); | |
| Serial.print(adc7); | |
| Serial.print(","); | |
| Serial.print(adc8); | |
| Serial.print(","); | |
| Serial.print(adc9); | |
| Serial.print(","); | |
| Serial.print(adc10); | |
| Serial.println(); | |
| M5.update(); | |
| delay(1000); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment