Hey everyone,
I'm working on a project where I'd like to control an Arduino Due with a touch screen on a Pi4. I'm using Node Red as the UI on the Pi and Standard Fermata for the Arduino. For now, I'm just trying to read a digital pin on the due, which is controlled by a Node Red flow, and print a message to an LCD screen (just to test communication). It appears that the natural state of digital pins 31-34 (the pins I'm using) is high as the LCD screen is printing "1" as the digitalRead on the pins. I've been able to get a flow working with a switch node and a stepper motor, but for some reason when I change to a button node, it stops working. Connections are all fine. I'm not sure if the problem is on the Arduino side or the NodeRed side. I wish I could be more specific, but I'm not entirely sure where I'm going wrong.
The entire sketch for Standard Fermata is too long to post but I made some simple changes to the setup and loop and added a few simple functions.
void printScare(){
lcd.print("Scaring");
delay(1000);
}
void printFight(){
lcd.print("Fighting");
delay(1000);
}
void printRest(){
lcd.print("Resting");
delay(1000);
}
void printConfuse(){
lcd.print("Confusing");
delay(1000);
}
void setup()
{
systemResetCallback();
pinMode(31, INPUT);
pinMode(32, INPUT);
pinMode(33, INPUT);
pinMode(34, INPUT);
Wire.begin();
//Serial.begin(9600);
Serial.println("\nI2C Scanner");
lcd._Addr = iicScanner();
lcd.init();
lcd.backlight();
lcd.print("IN SETUP");
Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
Firmata.attach(SET_PIN_MODE, setPinModeCallback);
Firmata.attach(SET_DIGITAL_PIN_VALUE, setPinValueCallback);
Firmata.attach(START_SYSEX, sysexCallback);
Firmata.attach(SYSTEM_RESET, systemResetCallback);
// to use a port other than Serial, such as Serial1 on an Arduino Leonardo or Mega,
// Call begin(baud) on the alternate serial port and pass it to Firmata to begin like this:
Serial1.begin(57600);
Firmata.begin(Serial1);
// However do not do this if you are using SERIAL_MESSAGE
Firmata.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for ATmega32u4-based boards and Arduino 101
}
lcd.clear();
}
/*==============================================================================
* LOOP()
*============================================================================*/
void loop(){
//lcd.print("IN LOOP");
lcd.clear();
if(digitalRead(31) == LOW){
printScare();
}
if(digitalRead(32) == LOW){
printFight();
}
if(digitalRead(33) == LOW){
printRest();
}
if(digitalRead(34) == LOW){
printConfuse();
}
byte pin, analogPin;
/* DIGITALREAD - as fast as possible, check for changes and output them to the
* FTDI buffer using Serial.print() */
//checkDigitalInputs();
/* STREAMREAD - processing incoming messagse as soon as possible, while still
* checking digital inputs. */
while (Firmata.available())
Firmata.processInput();
// TODO - ensure that Stream buffer doesn't go over 60 bytes
currentMillis = millis();
if (currentMillis - previousMillis > samplingInterval) {
previousMillis += samplingInterval;
/* ANALOGREAD - do all analogReads() at the configured sampling interval */
for (pin = 0; pin < TOTAL_PINS; pin++) {
if (IS_PIN_ANALOG(pin) && Firmata.getPinMode(pin) == PIN_MODE_ANALOG) {
analogPin = PIN_TO_ANALOG(pin);
if (analogInputsToReport & (1 << analogPin)) {
Firmata.sendAnalog(analogPin, analogRead(analogPin));
}
}
}
// report i2c data for all device with read continuous mode enabled
if (queryIndex > -1) {
for (byte i = 0; i < queryIndex + 1; i++) {
readAndReportData(query[i].addr, query[i].reg, query[i].bytes, query[i].stopTX);
}
}
}
#ifdef FIRMATA_SERIAL_FEATURE
serialFeature.update();
#endif
}
I'm still new to Node Red, so any help I could get there as well would be fantastic!
Thanks so much!