所有关于电路

关于7段显示的问题

mike_the_begginer

线程启动

mike_the_begginer

2019年12月7日加入
95
您好,我想使用Arduino建造焊接站。焊台有效,但代码可能存在错误,显示器不会按预期更新。当我旋转锅时,显示器(7段3位)显示从罐中读取的值,但显示器不会更新,因为焊接铁是加热的。
请看看代码,然后告诉我你的想法。

焊接站:
#include  #include  int thermoDO = 12;int thermoCS = 10;int thermoCLK = 13;MAX6675热电偶(thermoCLK, thermoCS, thermoDO);//保护int relay_pin = A5;0-9字节const digits[] = {B00111111, B00000110, B01011011, B01001111, B01100110, B01101101, B01111101, B00000111, B01111111, B01101111};int digit_common_pins[] = {A2, A3, A4};//三段7段LED显示屏常用引脚int max_digits = 3;Int current_digit = max_digits - 1;Unsigned long update = 1000; //Change how fast the display updates. No lower than 500 unsigned long lastupdate; int temperature = 0; //Define Variables we'll be connecting to double Setpoint, Input, Output; double heaterTemp; //Define the aggressive and conservative Tuning Parameters double aggKp = 4, aggKi = 0.2, aggKd = 1; double consKp = 1, consKi = 0.05, consKd = 0.25; //Specify the links and initial tuning parameters PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT); void setup() { DDRD = B11111111; // sets Arduino pins 0 to 7 as outputs for (int y = 0; y < max_digits; y++) { pinMode(digit_common_pins[y], OUTPUT); } //We do not want to drive the soldering iron at 100% because it may burn, so we set it to about 85% (220/255) myPID.SetOutputLimits(0, 220); myPID.SetMode(AUTOMATIC); lastupdate = millis(); Setpoint = 0; pinMode(relay_pin, OUTPUT); digitalWrite(relay_pin, LOW); delay(1000); digitalWrite(relay_pin, HIGH); } void loop() { // Read temperature heaterTemp = thermocouple.readCelsius(); Input = (0.779828 * heaterTemp) - 10.3427; //Display temperature if (isnan(heaterTemp) or Input >= 432) // No TC Connection OR over-temperature { while (true) { digitalWrite(relay_pin, LOW); digitalWrite(11, LOW); PORTD = B00000000; } } if (millis() - lastupdate > updaterate) { lastupdate = millis(); temperature = Input; } //Read setpoint and transform it into degrees celsius(minimum 150, maximum 350) double newSetpoint = analogRead(1); newSetpoint = map(newSetpoint, 0, 1023, 150, 400); //Display setpoint if (abs(newSetpoint - Setpoint) > 3) { Setpoint = newSetpoint; temperature = newSetpoint; lastupdate = millis(); } double gap = abs(Setpoint - Input); //distance away from setpoint if (gap < 10) { //we're close to setpoint, use conservative tuning parameters myPID.SetTunings(consKp, consKi, consKd); } else { //we're far from setpoint, use aggressive tuning parameters myPID.SetTunings(aggKp, aggKi, aggKd); } myPID.Compute(); //Drive the output analogWrite(11, Output); //Display the temperature if (temperature < 50){ show(50); } else { show(temperature); } } void show(int value) { int digits_array[] = {}; boolean empty_most_significant = true; for (int z = max_digits - 1; z >= 0; z--) //Cycle through each digit { digits_array[z] = value / pow(10, z); //We now take each digit from the number if (digits_array[z] != 0 ) empty_most_significant = false; //Do not display leading zeros value = value - digits_array[z] * pow(10, z); if (z == current_digit) { if (!empty_most_significant || z == 0) { //Check to see that we do not have leading zeros and display the current digit PORTD = digits[digits_array[z]]; //Remove ~ for common cathode } else { PORTD = B00000000; } digitalWrite(digit_common_pins[z], HIGH);//Change to LOW for common cathode } else { digitalWrite(digit_common_pins[z], LOW);//Change to HIGH for common cathode } } current_digit--; if (current_digit < 0) { current_digit = max_digits; //Start over } }
mike_the_begginer

线程启动

mike_the_begginer

2019年12月7日加入
95
LE:通过像这样修改loop(),它似乎可以工作。正确吗?Arduino是否正确读取MAX6675,在正确的时间间隔?
C:
Void loop() {if (millis() - lastupdate > update) {lastupdate = millis();//读取温度heaterTemp = thermocoupe . readcelsius ();输入= (0.779828 * heattemp) - 10.3427;//显示温度if (isnan(heaterTemp) or Input >= 432) //没有TC连接或超温{while (true) {digitalWrite(relay_pin, LOW);digitalWrite(11、低);PORTD = B00000000;}} temperature = Input;} //读取setpoint并将其转换为摄氏度(最小150度,最大350度)double newSetpoint = analogRead(A1);newSetpoint = map(newSetpoint, 0, 1023, 150, 400);//显示setpoint if (abs(newSetpoint - setpoint) > 3) {setpoint = newSetpoint; temperature = newSetpoint; lastupdate = millis(); } double gap = abs(Setpoint - Input); //distance away from setpoint if (gap < 10) { //we're close to setpoint, use conservative tuning parameters myPID.SetTunings(consKp, consKi, consKd); } else { //we're far from setpoint, use aggressive tuning parameters myPID.SetTunings(aggKp, aggKi, aggKd); } myPID.Compute(); //Drive the output analogWrite(11, Output); //Display the temperature if (temperature < 50) { show(50); } else { show(temperature); } }
最后的编辑:
KeithWalker

KeithWalker

2017年7月10日加入
1639年
试着调试别人的程序是相当困难和非常耗时的,因为我们不能运行它来查看到底发生了什么。我建议您尝试使用串行监视器来调试程序。
通过您的方式通过循环一次一点,添加串行。Print语句显示相关变量的值。在循环的末尾放一个延迟(1秒?),这样您就有时间读取结果。每次采样变量时,记录它们,然后停止程序。注释掉该串行。打印行并在程序的下一个操作部分添加更多的行。当您检查结果时,您可以确切地看到程序真正在做什么,并且您将对它偏离正轨的地方有一个良好的指示。
AlbertHall

AlbertHall

2014年6月4日加入
11187年
E

eetech00

2013年6月8日加入
2309年
你看,连Arduino都同意我说需要改进。IDE的这个版本是免费的,但是您还需要一个JTAG接口,据我所知,JTAG接口不是免费的。
所有这些只覆盖那些有JTAG接口的板。
TS没有具体说明是哪些董事会。
两者都是合理的建议。

您可以使用串行打印语句,但它们很难管理。
SamR

SamR

2019年3月19日加入
3226年
或者您可以在串行监视器中停止滚动才能查看正在发生的事情。编写串行监视器的代码可能不是“最佳”解决方案,但它是您必须在Arduino IDE中使用的。
AlbertHall

AlbertHall

2014年6月4日加入
11187年
Microchip MPLAB-X有,例如:
当将特定值写入特定变量时,停止程序。
在不需要硬件的模拟器中运行程序,并使用模拟的外部输入对程序的任何部分进行计时。
mike_the_begginer

线程启动

mike_the_begginer

2019年12月7日加入
95
在不同的论坛上搜索后,我发现了这个问题:MAX6675模块需要以至少250mS的间隔读取。在最初的代码中,程序的读取频率超过了250mS。我修改了如下程序,它工作了:


焊接站:
#include  #include  // max6675模块数据引脚int thermodo = 12;int thermoCS = 10;int thermoCLK = 13;MAX6675热电偶(thermoCLK, thermoCS, thermoDO);//保护引脚INT RELAY_PIN = A2;// int let_pin = 8;0-9字节const digits[] = {B00111111, B00000110, B01011011, B01001111, B01100110, B01101101, B01111101, B00000111, B01111111, B01101111};int digit_common_pins [] = {a3,a4,a5};//三段7段LED显示屏常用引脚int max_digits = 3;Int current_digit = max_digits - 1; unsigned long updaterate = 700; //Change how fast the display updates. No lower than 500 unsigned long lastupdate, lastupdate_max; int temperature = 0; //Define Variables we'll be connecting to double Setpoint, Input, Output; double heaterTemp; //Define the aggressive and conservative Tuning Parameters double aggKp = 4, aggKi = 0.2, aggKd = 1; double consKp = 1, consKi = 0.05, consKd = 0.25; //Specify the links and initial tuning parameters PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT); void setup() { DDRD = B11111111; // sets Arduino pins 0 to 7 as outputs for (int y = 0; y < max_digits; y++) { pinMode(digit_common_pins[y], OUTPUT); } //We do not want to drive the soldering iron at 100% because it may burn, so we set it to about 85% (220/255) myPID.SetOutputLimits(0, 220); myPID.SetMode(AUTOMATIC); lastupdate = millis(); lastupdate_max = millis(); Setpoint = 0; //pinMode(led_pin, OUTPUT); pinMode(relay_pin, OUTPUT); //digitalWrite(led_pin, LOW); digitalWrite(relay_pin, LOW); delay(1000); digitalWrite(relay_pin, HIGH); // turns on the relay to let the current flow to the soldering iron heater } void loop() { if (millis() - lastupdate_max > 250){ lastupdate_max = millis(); // Read temperature heaterTemp = thermocouple.readCelsius(); Input = (0.779828 * heaterTemp) - 10.3427; //estimate the temperature of the iron's tip, by reading the temperature of the iron's heater //Display error if (isnan(heaterTemp) or Input >= 432) // No TC Connection OR over-temperature { while (true) { digitalWrite(relay_pin, LOW);//cuts off the power to the soldering iron digitalWrite(11, LOW);//turns off the PID output PORTD = B00000000; // Turns off the entire display //digitalWrite(led_pin, HIGH); } } } //Display temperature if (millis() - lastupdate > updaterate) { lastupdate = millis(); temperature = Input; } //Read setpoint and transform it into degrees celsius(minimum 150, maximum 400) double newSetpoint = analogRead(A1); newSetpoint = map(newSetpoint, 0, 1023, 150, 400); //Display setpoint if (abs(newSetpoint - Setpoint) > 3) { Setpoint = newSetpoint; temperature = newSetpoint; lastupdate = millis(); } double gap = abs(Setpoint - Input); //distance away from setpoint if (gap < 10) { //we're close to setpoint, use conservative tuning parameters myPID.SetTunings(consKp, consKi, consKd); } else { //we're far from setpoint, use aggressive tuning parameters myPID.SetTunings(aggKp, aggKi, aggKd); } myPID.Compute(); // compute the pid output //Drive the output analogWrite(11, Output); //Display the temperature if (temperature < 50) { show(50); //display 50 if the estimated temperature is below 50C } else { show(temperature); //display the temperature } } void show(int value) { int digits_array[] = {}; boolean empty_most_significant = true; for (int z = max_digits - 1; z >= 0; z--) //Cycle through each digit { digits_array[z] = value / pow(10, z); //We now take each digit from the number if (digits_array[z] != 0 ) empty_most_significant = false; //Do not display leading zeros value = value - digits_array[z] * pow(10, z); if (z == current_digit) { if (!empty_most_significant || z == 0) { //Check to see that we do not have leading zeros and display the current digit PORTD = digits[digits_array[z]]; //Remove ~ for common cathode } else { PORTD = B00000000; } digitalWrite(digit_common_pins[z], HIGH);//Change to LOW for common cathode } else { digitalWrite(digit_common_pins[z], LOW);//Change to HIGH for common cathode } } current_digit--; if (current_digit < 0) { current_digit = max_digits; //Start over } }