I can get the Neopixel to work when I use the Neopixel simple.ino example and connect the Neopixel to MISO. I am assuming the Neopixel data connection needs to be connected to a SPI/CPU pin which is SCK, MOSI, MISO.
SCK and MOSI are connected to the TFT display. I would like to have the Neopixel connected on pin 12
Do I have a conflict with driving data to the TFT and Neopixel ? I found on the https://learn.adafruit.com/adafruit-esp ... er/pinouts
"ESP32 chips allow for 'multiplexing' of almost all signals so it isn't like some pins can do PWM and others can. You can connect any of the available PWM channels, I2S channels, UART, I2C or SPI ports to any pin. There are some exceptions....
The SPI pins are on the ESP32-S2 high-speed peripheral. You can set any pins to be the low-speed peripheral but you won't get the speedy interface!
SCK - This is the SPI clock pin.
MOSI - This is the SPI Microcontroller Out / Sensor In pin.
MISO - This is the SPI Microcontroller In / Sensor Out pin.
"
With the above exceptions should I be able to have a low speed peripheral on pin 12 for the Neopixel ? What would be considered low speed ? Or will having the display not support running Neopixels also ?
Thank you!
Code: Select all
#include "Adafruit_seesaw.h"
#include <Arduino.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_DotStar.h>
#include <ezButton.h>
#include <Adafruit_BusIO_Register.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
Adafruit_seesaw ss;
#define NAME_PLATE_PIN 12
// #define CLOCKPIN SCK
#define NAME_PLATE_NUMPIXELS 2
Adafruit_NeoPixel nameplate(NAME_PLATE_NUMPIXELS, NAME_PLATE_PIN, NEO_RGBW + NEO_KHZ800);
int TFT_CS = 5;
int TFT_DC = 9;
int TFT_RST = 6;
int TFT_BACKLITE = 10;
int LED = 13;
int motion_pin = 11;
int COLOR_BUTTON = 4;
int color_button_new = 0;
int color_button_old = 0;
int color = 0;
int old_color = 0;
int new_color = 0;
int motion = 0;
int motion_state = LOW;
bool temp_change = 0;
bool cap_change = 0;
float last_tempC = 0;
uint16_t last_cap = 0;
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
float p = 3.1415926;
void setup() {
pinMode(LED, OUTPUT);
pinMode(motion_pin, INPUT);
pinMode(TFT_BACKLITE, OUTPUT);
pinMode(COLOR_BUTTON, INPUT);
digitalWrite(TFT_BACKLITE, HIGH);
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
Serial.begin(9600);
tft.init(240, 240);
tft.setRotation(0);
tft.fillScreen(ST77XX_BLACK);
delay(1000);
tft.fillScreen(ST77XX_RED);
delay(10000);
tft.fillScreen(ST77XX_GREEN);
delay(10000);
tft.fillScreen(ST77XX_BLACK);
nameplate.begin();
nameplate.setBrightness(100);
nameplate.setPixelColor(0, nameplate.Color(255,0,0));
uint16_t time = millis();
time = millis() - time;
Serial.println("seesaw Soil Sensor example!");
if (!ss.begin(0x36)) {
Serial.println("ERROR! seesaw not found");
while(1) delay(1);
} else {
Serial.print("seesaw started! version: ");
Serial.println(ss.getVersion(), HEX);
}
delay(1000);
}
void loop() {
float tempC = ss.getTemp();
uint16_t capread = ss.touchRead(0);
bool temp_change = ((tempC > (last_tempC * (1.05))) || (tempC < (last_tempC * (0.95))));
bool cap_change = ((capread > (last_cap * (1.05))) || (capread < (last_cap * (0.95))));
int tempF = ((tempC * 9/5) + 32);
if (temp_change == true) {
Serial.print("Temperature: "); Serial.print(tempC); Serial.println("*C");
tft.setCursor(20, 10);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(4);
tft.fillRect(20, 20, 125, 20, ST77XX_BLACK);
tft.println(tempF);
tft.setCursor(90, 10);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(4);
tft.println("F");
Serial.println("Motion detected!");
Serial.println(last_tempC);
Serial.println(temp_change);
}
else {
}
if (cap_change == true) {
// tft.setCursor(10, 150);
// tft.fillRect(10, 150, 150, 30, ST77XX_BLACK);
// tft.setTextColor(ST77XX_BLUE);
// tft.setTextSize(4);
// tft.println(capvalue);
if (capread > 500) {
tft.setTextColor(ST77XX_GREEN);
tft.setTextSize(4);
tft.setCursor(10, 50);
tft.fillRect(10, 50, 175, 30, ST77XX_BLACK);
tft.println("GOOD");
}
else {
tft.setTextColor(ST77XX_RED);
tft.setTextSize(4);
tft.setCursor(10, 50);
tft.fillRect(10, 50, 175, 30, ST77XX_BLACK);
tft.println("WATER!");
}
// Serial.println("Motion detected!");
// Serial.print("Capacitive: "); Serial.println(capread);
}
else {
}
last_tempC = tempC;
last_cap = capread;
delay(1000);
motion = digitalRead(motion_pin); // read input value
if (motion == HIGH) { // check if the input is HIGH
digitalWrite(LED, HIGH); // turn LED ON
if (motion_state == LOW) {
tft.setCursor(20, 100);
tft.fillScreen(ST77XX_RED);
tft.setTextColor(ST77XX_BLACK);
tft.setTextSize(4);
tft.fillRect(5, 100, 200, 40, ST77XX_RED);
tft.print("INVADER!!");
Serial.println("Motion detected!");
// We only want to print on the output change, not state
motion_state = HIGH;
}
} else {
digitalWrite(LED, LOW); // turn LED OFF
if (motion_state == HIGH){
// we have just turned of
tft.setCursor(40, 100);
tft.setTextColor(ST77XX_BLACK);
tft.setTextSize(4);
tft.fillRect(5, 150, 200, 40, ST77XX_GREEN);
tft.fillScreen(ST77XX_GREEN);
tft.print("CLEAR!");
Serial.println("Motion ended!");
delay(5000);
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(20, 10);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(4);
tft.fillRect(20, 20, 125, 20, ST77XX_BLACK);
tft.println(tempF);
tft.setCursor(90, 10);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(4);
tft.println("F");
if (capread > 500) {
tft.setTextColor(ST77XX_GREEN);
tft.setTextSize(4);
tft.setCursor(10, 50);
tft.fillRect(10, 50, 175, 30, ST77XX_BLACK);
tft.println("GOOD");
}
else {
tft.setTextColor(ST77XX_RED);
tft.setTextSize(4);
tft.setCursor(10, 50);
tft.fillRect(10, 50, 175, 30, ST77XX_BLACK);
tft.println("WATER!");
}
// We only want to print on the output change, not state
motion_state = LOW;
}
}
bool color_button_new = digitalRead(COLOR_BUTTON);
if((color_button_new == LOW) && (color_button_old == HIGH)) {
delay(50);
color_button_new = digitalRead(COLOR_BUTTON);
if(++color > 2) color = 0;
switch(color) {
case 0:
nameplate.setPixelColor(2, nameplate.Color(255, 0, 0));
break;
case 1:
nameplate.setPixelColor(2, nameplate.Color(0, 255, 0));
break;
}
}
color_button_old = color_button_new;
}