feat: added configurations for i2c communication between devices
This commit is contained in:
+13
-1
@@ -1 +1,13 @@
|
|||||||
# Architektoniczne perełki Lublina - Master
|
# Architektoniczne perełki Lublina - Master
|
||||||
|
|
||||||
|
## I2C
|
||||||
|
Pins:
|
||||||
|
- SDA -> 21
|
||||||
|
- SCL -> 22
|
||||||
|
|
||||||
|
Addresses:
|
||||||
|
- Slave 1 -> `0x08`
|
||||||
|
- Slave 2 -> `0x09`
|
||||||
|
- Slave 3 -> `0x0A`
|
||||||
|
- Slave 4 -> `0x0B`
|
||||||
|
- Slave 5 -> `0x0C`
|
||||||
@@ -12,5 +12,6 @@
|
|||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|
||||||
|
lib_deps = fastled/FastLED@^3.10.3
|
||||||
|
|||||||
@@ -1,11 +1,53 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <FastLED.h>
|
||||||
|
|
||||||
|
#define SDA_PIN 21
|
||||||
|
#define SCL_PIN 22
|
||||||
|
|
||||||
|
#define SLAVE_ONE_ADDRESS 0x08
|
||||||
|
#define SLAVE_TWO_ADDRESS 0x09
|
||||||
|
#define SLAVE_THREE_ADDRESS 0x0A
|
||||||
|
#define SLAVE_FOUR_ADDRESS 0x0B
|
||||||
|
#define SLAVE_FIVE_ADDRESS 0x0C
|
||||||
|
|
||||||
|
#define LED_DATA_PIN 5
|
||||||
|
#define LED_COUNT 29
|
||||||
|
#define BRIGHTNESS 64
|
||||||
|
#define LED_TYPE WS2812B
|
||||||
|
#define COLOR_ORDER GRB
|
||||||
|
|
||||||
|
CRGB leds[LED_COUNT];
|
||||||
|
|
||||||
|
const CRGB SUCCESS_COLOR = CRGB::Green;
|
||||||
|
const CRGB ERROR_COLOR = CRGB::Red;
|
||||||
|
|
||||||
|
void testLedStrip();
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN);
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
// Initialize FastLED with the specified LED type, data pin, and LED count
|
||||||
|
FastLED.addLeds<LED_TYPE, LED_DATA_PIN, COLOR_ORDER>(leds, LED_COUNT).setCorrection(TypicalLEDStrip);
|
||||||
|
FastLED.setBrightness(BRIGHTNESS);
|
||||||
|
testLedStrip();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testLedStrip()
|
||||||
|
{
|
||||||
|
// Test the LED strip by turning on each LED one by one
|
||||||
|
for (int i = 0; i < LED_COUNT; i++)
|
||||||
|
{
|
||||||
|
leds[i] = SUCCESS_COLOR; // Set the LED to green
|
||||||
|
FastLED.show();
|
||||||
|
delay(100); // Wait for a short duration
|
||||||
|
leds[i] = CRGB::Black; // Turn off the LED
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,8 @@
|
|||||||
# Architektoniczne perełki Lublina - Slave 1
|
# Architektoniczne perełki Lublina - Slave 1
|
||||||
|
|
||||||
|
## I2C
|
||||||
|
Pins:
|
||||||
|
- SDA -> 21
|
||||||
|
- SCL -> 22
|
||||||
|
|
||||||
|
Address: 0x08
|
||||||
@@ -1,10 +1,29 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#define SDA_PIN 21
|
||||||
|
#define SCL_PIN 22
|
||||||
|
|
||||||
|
#define SLAVE_ADDRESS 0x08
|
||||||
|
|
||||||
|
void requestEvent();
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins
|
||||||
|
|
||||||
|
Wire.onRequest(requestEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void requestEvent()
|
||||||
|
{
|
||||||
|
// TODO: Send data to the master when requested
|
||||||
|
Serial.println("Master requested data from Slave.");
|
||||||
|
Wire.write("Hello from Slave!");
|
||||||
|
}
|
||||||
@@ -1 +1,8 @@
|
|||||||
# Architektoniczne perełki Lublina - Slave 2
|
# Architektoniczne perełki Lublina - Slave 2
|
||||||
|
|
||||||
|
## I2C
|
||||||
|
Pins:
|
||||||
|
- SDA -> 21
|
||||||
|
- SCL -> 22
|
||||||
|
|
||||||
|
Address: 0x09
|
||||||
@@ -1,11 +1,29 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#define SDA_PIN 21
|
||||||
|
#define SCL_PIN 22
|
||||||
|
|
||||||
|
#define SLAVE_ADDRESS 0x09
|
||||||
|
|
||||||
|
void requestEvent();
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins
|
||||||
|
|
||||||
|
Wire.onRequest(requestEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// put your main code here, to run repeatedly:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void requestEvent()
|
||||||
|
{
|
||||||
|
// TODO: Send data to the master when requested
|
||||||
|
Serial.println("Master requested data from Slave.");
|
||||||
|
Wire.write("Hello from Slave!");
|
||||||
|
}
|
||||||
@@ -1 +1,8 @@
|
|||||||
# Architektoniczne perełki Lublina - Slave 3
|
# Architektoniczne perełki Lublina - Slave 3
|
||||||
|
|
||||||
|
## I2C
|
||||||
|
Pins:
|
||||||
|
- SDA -> 21
|
||||||
|
- SCL -> 22
|
||||||
|
|
||||||
|
Address: 0x0A
|
||||||
@@ -1,11 +1,29 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#define SDA_PIN 21
|
||||||
|
#define SCL_PIN 22
|
||||||
|
|
||||||
|
#define SLAVE_ADDRESS 0x0A
|
||||||
|
|
||||||
|
void requestEvent();
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins
|
||||||
|
|
||||||
|
Wire.onRequest(requestEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// put your main code here, to run repeatedly:
|
}
|
||||||
|
|
||||||
|
void requestEvent()
|
||||||
|
{
|
||||||
|
// TODO: Send data to the master when requested
|
||||||
|
Serial.println("Master requested data from Slave.");
|
||||||
|
Wire.write("Hello from Slave!");
|
||||||
}
|
}
|
||||||
@@ -1 +1,8 @@
|
|||||||
# Architektoniczne perełki Lublina - Slave 4
|
# Architektoniczne perełki Lublina - Slave 4
|
||||||
|
|
||||||
|
## I2C
|
||||||
|
Pins:
|
||||||
|
- SDA -> 21
|
||||||
|
- SCL -> 22
|
||||||
|
|
||||||
|
Address: 0x0B
|
||||||
@@ -1,10 +1,29 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#define SDA_PIN 21
|
||||||
|
#define SCL_PIN 22
|
||||||
|
|
||||||
|
#define SLAVE_ADDRESS 0x0B
|
||||||
|
|
||||||
|
void requestEvent();
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins
|
||||||
|
|
||||||
|
Wire.onRequest(requestEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void requestEvent()
|
||||||
|
{
|
||||||
|
// TODO: Send data to the master when requested
|
||||||
|
Serial.println("Master requested data from Slave.");
|
||||||
|
Wire.write("Hello from Slave!");
|
||||||
|
}
|
||||||
@@ -1 +1,8 @@
|
|||||||
# Architektoniczne perełki Lublina - Slave 5
|
# Architektoniczne perełki Lublina - Slave 5
|
||||||
|
|
||||||
|
## I2C
|
||||||
|
Pins:
|
||||||
|
- SDA -> 21
|
||||||
|
- SCL -> 22
|
||||||
|
|
||||||
|
Address: 0x0C
|
||||||
@@ -1,10 +1,29 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#define SDA_PIN 21
|
||||||
|
#define SCL_PIN 22
|
||||||
|
|
||||||
|
#define SLAVE_ADDRESS 0x0C
|
||||||
|
|
||||||
|
void requestEvent();
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN, SLAVE_ADDRESS); // Initialize I2C with specified SDA and SCL pins
|
||||||
|
|
||||||
|
Wire.onRequest(requestEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void requestEvent()
|
||||||
|
{
|
||||||
|
// TODO: Send data to the master when requested
|
||||||
|
Serial.println("Master requested data from Slave.");
|
||||||
|
Wire.write("Hello from Slave!");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user