ManMadeDesaster
New member
Hello,
i have a Teensy 4.0 and a nextion display with the io adapter. I use some of the nextion io pins as output (3.3v), which are directly wired to the inputs of the teensy. when i press a button on the display an output gets high and when i release it the output gets low. i programmed the teensy to output 3.3v via a resistor into an optocoupler, which then "switches" the other side to power a led.
this works except the output of the teensy stays high even though the output of the nextion, which goes into the input of the teensy, is low. i tried INPUT_PULLUP as well as INPUT_PULLDOWN but its the same. I have to manually set the inputs low like this: digitalWrite(bwd, LOW);
this is my code (totally not finished beginner noob code ):
is this normal behaviour? i remember that the output is high as long as the input is high. If the input is low then the output should also get low.
i have a Teensy 4.0 and a nextion display with the io adapter. I use some of the nextion io pins as output (3.3v), which are directly wired to the inputs of the teensy. when i press a button on the display an output gets high and when i release it the output gets low. i programmed the teensy to output 3.3v via a resistor into an optocoupler, which then "switches" the other side to power a led.
this works except the output of the teensy stays high even though the output of the nextion, which goes into the input of the teensy, is low. i tried INPUT_PULLUP as well as INPUT_PULLDOWN but its the same. I have to manually set the inputs low like this: digitalWrite(bwd, LOW);
this is my code (totally not finished beginner noob code ):
Code:
#include <AccelStepper.h>
#include <TMC2208Stepper.h>
#include <TMC2208Stepper_REGDEFS.h>
TMC2208Stepper driver = TMC2208Stepper(&Serial1);
AccelStepper stepper(1, 3, 4); // 1= Easy Driver interface
// Pin 3 Step
// Pin 4 Dir
const int EN_PIN = 2;
const int STEP_PIN = 3;
const int DIR_PIN = 4;
const int end_1 = 9;
const int end_2 = 10;
const int focus = 11;
const int shutter = 12;
const int led = 13;
const int fwd = 14;
const int bwd = 15;
const int cycle_stop = 16;
const int cycle_start = 17;
const int set_param = 18;
int ledState = LOW; // ledState used to set the LED
unsigned long previousMillis = 0; // will store last time LED was updated
const long blinkTime = 1000; // interval at which to blink (milliseconds)
boolean ready, runallowed = false;
void setup() {
Serial.begin(115200); //Computer
Serial1.begin(115200); //TMC2208
Serial2.begin(921600); //Nextion
//while(!Serial);
while(!Serial1);
while(!Serial2);
Serial2.print("page0.t0.txt=\"Verbunden\"");
Serial2.write(0xff);
Serial2.write(0xff);
Serial2.write(0xff);
pinMode(fwd, INPUT_PULLDOWN); // Vorwärts
pinMode(bwd, INPUT_PULLDOWN); // Rückwärts
pinMode(cycle_stop, INPUT_PULLDOWN); // Stoppen
pinMode(cycle_start, INPUT_PULLDOWN); // Starten
pinMode(set_param, INPUT_PULLDOWN); // Start/Endpunkt setzen
pinMode(end_1, INPUT_PULLUP); // Endschalter 1
pinMode(end_2, INPUT_PULLUP); // Endschalter 2
pinMode(EN_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
pinMode(focus, OUTPUT);
pinMode(shutter, OUTPUT);
pinMode(led, OUTPUT);
stepper.setMaxSpeed(1000.0);
stepper.setAcceleration(4000.0);
driver.pdn_disable(1); // Use PDN/UART pin for communication
driver.I_scale_analog(0); // Adjust current from the registers
driver.rms_current(700); // Set driver current 500mA
driver.toff(0x2); // Enable driver
driver.mstep_reg_select(1); // Microstep resolution selected by MSTEP register
driver.microsteps(4); // [0..256] Set number of microsteps
driver.shaft(0); // Drehrichtung Motor
delay (500);
digitalWrite(EN_PIN, LOW); // Enable driver
digitalWrite(led, HIGH); // Status LED Pin 13
}
void loop() {
stepper.run();
ledTime();
io();
}
void ledTime(){
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= blinkTime) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(led, ledState);
}
}
void io(){
digitalWrite(shutter, LOW);
digitalWrite(focus, LOW);
digitalWrite(fwd, LOW);
digitalWrite(bwd, LOW);
if(digitalRead(end_1) == LOW){
stepper.move(100);
}
if(digitalRead(end_2) == LOW){
stepper.move(-100);
}
if(digitalRead(set_param) == HIGH){
}
if(digitalRead(fwd) == HIGH){
stepper.move(100);
}
if(digitalRead(bwd) == HIGH){
stepper.move(-100);
}
if(digitalRead(cycle_stop) == HIGH){
stepper.stop();
}
if(digitalRead(cycle_start) == HIGH){
cycleStart();
}
}
void cycleStart(){
digitalWrite(focus, HIGH);
digitalWrite(shutter, HIGH);
}
is this normal behaviour? i remember that the output is high as long as the input is high. If the input is low then the output should also get low.