Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Dec 29, 2023
1 parent 38b977e commit 0e82832
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/TCA9548_demo_AM2320/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:

packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
- esp8266
# - mega2560
- rpipico
libraries:
- "AM232X"
- "TCA9548"
81 changes: 81 additions & 0 deletions examples/TCA9548_demo_AM2320/TCA9548_demo_AM2320.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// FILE: TCA9548_demo_AM2320.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo TCA9548 I2C multiplexer
// URL: https://github.com/RobTillaart/TCA9548


#include "AM232X.h"
#include "TCA9548.h"

PCA9546 MP(0x70);
uint8_t channels = 0;

AM232X living; // channel 0
AM232X kitchen; // channel 1
AM232X outside; // channel 2

uint32_t lastTime = 0;

void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("TCA9548_LIB_VERSION: ");
Serial.println(TCA9548_LIB_VERSION);
Serial.print("AM232X_LIB_VERSION: ");
Serial.println(AM232X_LIB_VERSION);
Serial.println();

Wire.begin();
// initialize multiplexer
if (MP.begin() == false)
{
Serial.println("Multiplexer error");
}
channels = MP.channelCount();

// initialize the temperature sensors
MP.selectChannel(0);
if (living.begin() == false)
{
Serial.println("living error");
}
MP.selectChannel(1);
if (kitchen.begin() == false )
{
Serial.println("kitchen error");
}
MP.selectChannel(2);
if (outside.begin() == false )
{
Serial.println("outside error");
}
}


void loop()
{
if ((millis() - lastTime) > 5000)
{
lastTime = millis();

MP.selectChannel(0);
living.read();
Serial.print(living.getTemperature(), 1);
Serial.print("\t");

MP.selectChannel(1);
kitchen.read();
Serial.print(kitchen.getTemperature(), 1);
Serial.print("\t");

MP.selectChannel(2);
outside.read();
Serial.print(outside.getTemperature(), 1);
Serial.print("\n");
}
}


// -- END OF FILE --

0 comments on commit 0e82832

Please sign in to comment.