Ran into a weird problem today. For some reason, using this code, breaks pin 0 for RX using Arduino IDE (2.3.2) :
#define SENSOR_TIMEOUT 2000 // 2 seconds timeout
#define COOLDOWN_TIME 5000 // 5 seconds cooldown period
#define NUM_SENSORS 30
int sensorPins[NUM_SENSORS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}; // Pin numbers for sensors
int sensorState[NUM_SENSORS]; // Store sensor states
unsigned long lastTrigger[NUM_SENSORS]; // Track when sensors were last triggered
void setup() {
Serial.begin(9600); // Set baud rate for communication
while(!Serial);
Serial1.begin(9600);
while(!HWSERIAL);
for (int i = 0; i < NUM_SENSORS; i++) {
pinMode(sensorPins, INPUT_PULLUP); // Set sensor pins as input with pull-up resistors
lastTrigger = 0; // Initialize last trigger times }
Serial.println("Serial start");
}
void loop() {
// Check if any data is available on Serial1
if (Serial1.available()) {
// Read the incoming message
String receivedMessage = Serial1.readString();
// Print the received message on Serial (USB)
Serial.println("Message received: " + receivedMessage);
}
}
Once I comment this line: pinMode(sensorPins, INPUT_PULLUP); // Set sensor pins as input with pull-up resistors
everything seems to work. Otherwise, no data is received when that line is left in.
Anyone have an idea what I am missing? Or am I doing something wrong?
Reading this from the main Teensy 4.1 page:
Digital Input Pins
Digital pins may be used to receive signals. Teensy 4.1 pins default to INPUT most with a "keeper" resistor. Teensy 4.1 pins accept 0 to 3.3V signals. The pins are not 5V tolerant. Do not drive any digital pin higher than 3.3V.
Input Pullup / Pulldown / Keeper Resistors
All digital pins have optional pullup, pulldown, or keeper resistors. These are used to keep the pin at logic HIGH or logic LOW or the same logic level when it is not being actively driven by external circuity. Normally these resistors are used with pushbuttons & switches. The pinMode function with INPUT_PULLUP or INPUT_PULLDOWN must be used to configure these pins to input mode with the built-in resistor.
I am assuming they are all INPUTs anyway, and I don't really need the built-in resistors. I have sensors hooked up to all of these pins that are listed in the array and they seem to function without this line in there anyway. But I figured I would post and get some feedback.
Thanks!
Aaron
#define SENSOR_TIMEOUT 2000 // 2 seconds timeout
#define COOLDOWN_TIME 5000 // 5 seconds cooldown period
#define NUM_SENSORS 30
int sensorPins[NUM_SENSORS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}; // Pin numbers for sensors
int sensorState[NUM_SENSORS]; // Store sensor states
unsigned long lastTrigger[NUM_SENSORS]; // Track when sensors were last triggered
void setup() {
Serial.begin(9600); // Set baud rate for communication
while(!Serial);
Serial1.begin(9600);
while(!HWSERIAL);
for (int i = 0; i < NUM_SENSORS; i++) {
pinMode(sensorPins, INPUT_PULLUP); // Set sensor pins as input with pull-up resistors
lastTrigger = 0; // Initialize last trigger times }
Serial.println("Serial start");
}
void loop() {
// Check if any data is available on Serial1
if (Serial1.available()) {
// Read the incoming message
String receivedMessage = Serial1.readString();
// Print the received message on Serial (USB)
Serial.println("Message received: " + receivedMessage);
}
}
Once I comment this line: pinMode(sensorPins, INPUT_PULLUP); // Set sensor pins as input with pull-up resistors
everything seems to work. Otherwise, no data is received when that line is left in.
Anyone have an idea what I am missing? Or am I doing something wrong?
Reading this from the main Teensy 4.1 page:
Digital Input Pins
Digital pins may be used to receive signals. Teensy 4.1 pins default to INPUT most with a "keeper" resistor. Teensy 4.1 pins accept 0 to 3.3V signals. The pins are not 5V tolerant. Do not drive any digital pin higher than 3.3V.
Input Pullup / Pulldown / Keeper Resistors
All digital pins have optional pullup, pulldown, or keeper resistors. These are used to keep the pin at logic HIGH or logic LOW or the same logic level when it is not being actively driven by external circuity. Normally these resistors are used with pushbuttons & switches. The pinMode function with INPUT_PULLUP or INPUT_PULLDOWN must be used to configure these pins to input mode with the built-in resistor.
I am assuming they are all INPUTs anyway, and I don't really need the built-in resistors. I have sensors hooked up to all of these pins that are listed in the array and they seem to function without this line in there anyway. But I figured I would post and get some feedback.
Thanks!
Aaron