electronics.forumgreek.com
Θέλετε να αντιδράσετε στο μήνυμα; Φτιάξτε έναν λογαριασμό και συνδεθείτε για να συνεχίσετε.

Μια μικρή βοήθεια σε arduino!

2 απαντήσεις

Πήγαινε κάτω

Μια μικρή βοήθεια σε arduino! Empty Μια μικρή βοήθεια σε arduino!

Δημοσίευση από billtsig Κυρ Μάης 22, 2016 4:52 pm

καλησπέρα παιδιά και χρονια πολλά στους εορτάζοντες


χρειάζομαι μια μικρή βοήθεια σχετικά με τον σταθμό κολλήσεις που προσπαθώ να κατασκευάσω


χρησιμοποιώ το ακόλουθο πρόγραμμα (στο 2ο post μου)και προσπαθώ να έχω μέτρηση της θερμοκρασίας με το max6675 έχω κάνει την ακόλουθη τροποποίηση και ενώ όλα δείχνουν να δουλεύουν μια χαρά αντιμετωπίζω πρόβλημα με το pid autotune συμπεριφέρεται σαν να μην μεταβάλλεται η θερμοκρασία πχ το τροφοδοτικό τραβάει μόνιμα 400mA και δεν παίζει με το duty cycle


με τελεστικό που το δοκίμασα δούλευε κανονικά το pid autotune


κάθε βοήθεια σας θα ήταν πολύτιμη ευχαριστώ πολύ

billtsig

Μηνύματα : 97
Εγγραφή : 16/11/2012
Τόπος : Αθήνα

Επιστροφή στην κορυφή Πήγαινε κάτω

Μια μικρή βοήθεια σε arduino! Empty Απ: Μια μικρή βοήθεια σε arduino!

Δημοσίευση από billtsig Κυρ Μάης 22, 2016 4:53 pm

Κώδικας:
  /*******************************************************************************************Soldering Station controller for Chinese Hakko 907
Original code by Kuro - https://hackaday.io/project/3417-hakko-907-based-soldering-station
Edited by Yannis Kari - https://hackermagnet.com
version 0.1
********************************************************************************************/


#include <Wire.h>
#include "LiquidCrystal.h"
#include "TimerOne.h"
#include "Button.h"
#include "PID_v1.h"
#include "PID_AutoTune_v0.h"
#include "EEPROMex.h"
#include <avr/wdt.h>
#include <max6675.h>


#define OFF 0
#define ON 1


// PIN DEFINITIONS


#define HEATER 10
//#define TEMP_PIN 18
#define POT 19
#define Button1 8
#define Button2 7
#define Button3 2
#define Button4 4
//LCD
#define LCD_LED          9
#define LCD_RS 17
#define LCD_EN 16
#define LCD_D4 15
#define LCD_D5 14
#define LCD_D6 12
#define LCD_D7 11
//LED
const int LED_R = 3;
const int LED_G = 5;
const int LED_B = 6;
int flash_on = 0;
int flash_off = 0;


int thermoDO = 0;
int thermoCS = 18;
int thermoCLK =1;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
//SETTINGS


#define LCD_INTERVAL 200 // Time im ms between LCD updates
#define PTC_INTERVAL 300 // Time im ms between average analog readings
#define FLASH_ON 600 // Time im ms for RGB to stay on when flashing
#define FLASH_OFF 400 // Time im ms for RGB to stay off when flashing
#define RGB_EFECT_MIN 60 // degrees below temperature to start the RGB effect
#define RGB_EFECT_MAX 30 // degrees above temperature to finish the RGB effect
#define TEMP_WO_IRON 0 // readTemp(); returns about 749 when I disconnect the iron


// Y = a*X + b, where Y is the temperature and X is the analog value read from the sensor.
#define EQUATION_A  0.60
#define EQUATION_B 0


// Temperature control definitions
#define MIN_TEMP 150 // Minimum setpoint temperature
#define MAX_TEMP 395 // Maximum setpoint temperature
#define PWM_MAX 1023 // PWM limit, max 1023 (my power supply was shutting down at 1023)


// PID VALUES
#define KP_VAL 26.67
#define KI_VAL 3.56
#define KD_VAL 50.01


// PID Autotune Variables
#define AUTOTUNE_SETPOINT 200 // Temperature around PID autotune will tune
#define AUTOTUNE_START_VALUE (PWM_MAX/2) // Do not change
#define AUTOTUNE_STEP_VALUE AUTOTUNE_START_VALUE // Do not change
#define AUTOTUNE_NOISEBAND 3
#define AUTOTUNE_LOOKBACK 10


int bright = 10; //brightness of LCD (1..10)
uint8_t showAnalog = OFF; //show analog values in PID values view


// Global variables
uint32_t last_lcd_update = 0;
uint32_t last_ptc_update = 0;
uint8_t heater_mode = OFF;
uint8_t autotune = OFF;
uint8_t showPID = OFF;


// PID Variables
double temperature;
double setpoint = 0.0;
double duty;
double kp;
double ki;
double kd;
uint16_t kp_address;
uint16_t ki_address;
uint16_t kd_address;
uint16_t bright_address;


PID heaterPid(&temperature, &duty, &setpoint, 2, 5, 1, DIRECT);
PID_ATune aTune(&temperature, &duty);
LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
Button heatButton = Button(Button1, LOW);
Button decreaseBrightButton = Button(Button2, LOW);
Button increaseBrightButton = Button(Button3, LOW);
Button pidButton = Button(Button4, LOW);


void setup() {
 //Serial.begin(9600);
 // Enable Watchdog Timer, 1 second
 wdt_enable(WDTO_1S);


 // Define the EEPROM address for Kp, Ki and Kd
 kp_address = EEPROM.getAddress(sizeof(double));
 ki_address = EEPROM.getAddress(sizeof(double));
 kd_address = EEPROM.getAddress(sizeof(double));
 bright_address = EEPROM.getAddress(sizeof(int));
 
 // Set up pins
 pinMode(LCD_LED, OUTPUT);
 pinMode(HEATER, OUTPUT);
 pinMode(LED_R, OUTPUT);
 pinMode(LED_G, OUTPUT);
 pinMode(LED_B, OUTPUT);  
 pinMode(Button1, INPUT_PULLUP);
 pinMode(Button2, INPUT_PULLUP);
 pinMode(Button3, INPUT_PULLUP);
 pinMode(Button4, INPUT_PULLUP);


 // Set up Heater PWM
 Timer1.pwm(HEATER,  0 , 30);
 
 // Set up PID
 heaterPid.SetOutputLimits(0, PWM_MAX);
 heaterPid.SetMode(AUTOMATIC);
 
 // Set up LCD
 bright = EEPROM.readInt(bright_address);
 setBrightness(bright);
 lcd.begin(16, 2);
 charSetup();


 // Check if PID autotune button is pressed at startup
 if(digitalRead(Button4) == 0) {
 autotune = ON;
 }
 
 // Start PID autotune procedure if button was pressed
 if(autotune == ON) {
 // Configure PID autotune
 setpoint = AUTOTUNE_SETPOINT;
 duty = AUTOTUNE_START_VALUE;
 aTune.SetNoiseBand(AUTOTUNE_NOISEBAND);
 aTune.SetOutputStep(AUTOTUNE_STEP_VALUE);
 aTune.SetLookbackSec(AUTOTUNE_LOOKBACK);
 aTune.SetControlType(1);
 
 // Print some autotune info
 lcd.clear();
 lcd.print("PID Autotune at:");
 lcd.setCursor(0, 1);
 lcd.print((uint16_t)setpoint);
 lcd.print((char)223);
 lcd.print("C");
 
 // Heat to the setpoint, temperature will rise above it
 Timer1.setPwmDuty(HEATER, duty);
 while(readTemp() < setpoint) {
 // Reset the watchdog timer to prevent rebooting
 wdt_reset();
 }
 
 // Wait for temperature to drop to setpoint
 Timer1.setPwmDuty(HEATER, 0);
 while(readTemp() > setpoint) {
 // Reset the watchdog timer to prevent rebooting
 wdt_reset();
 }
 // Start the autotune
 while(autotune == ON) {
 // Get the current temperature
 temperature = readTemp();
 
 // Check if the autotune is finished
 if(aTune.Runtime() != 0) {
 autotune = OFF;
 }
 else {
 Timer1.setPwmDuty(HEATER, duty);
 }
 
 // If finished, set up the PID and EEPROM values
 if(autotune == OFF) {
 
 // Turn off the heater
 Timer1.setPwmDuty(HEATER, 0);
 
 // Get the values from autotune
 kp = aTune.GetKp();
 ki = aTune.GetKi();
 kd = aTune.GetKd();
 
 // Write them to the EEPROM
 EEPROM.writeDouble(kp_address, kp);
 EEPROM.writeDouble(ki_address, ki);
 EEPROM.writeDouble(kd_address, kd);
 
 // Reset the setpoint
 setpoint = 0.0;
 }
 
 // Reset the watchdog timer to prevent rebooting
 wdt_reset();
 }
 }
 
 // Get the PID constant values from EEPROM
 kp = EEPROM.readDouble(kp_address);
 ki = EEPROM.readDouble(ki_address);
 kd = EEPROM.readDouble(kd_address);
 
 // Set the to the PID
 //heaterPid.SetTunings(kp,ki,kd);
 heaterPid.SetTunings(kp,ki,kd);
 
 // Clear the display
 lcd.clear();
}


void loop() {
 uint32_t current_time = millis(); // Get the current time


 wdt_reset(); // Reset the watchdog timer to prevent rebooting
 checkButton(); // Check the  buttons
 setpoint = readPot(); //Read Setpoint
 if(current_time - last_ptc_update > PTC_INTERVAL) {
 temperature = readTemp(); // Read Analog data for PTC
 if(heater_mode == ON) lightRGB(setpoint, temperature);
 last_ptc_update = current_time;
 }


 heaterPid.Compute(); // Calculate PID value
 // Adjust PWM Duty based on the PID
 if(heater_mode == ON) {
 Timer1.setPwmDuty(HEATER, duty);
 } else {
 Timer1.setPwmDuty(HEATER, 0);
 }


 //Check if it's time to update the LCD
 if(current_time - last_lcd_update > LCD_INTERVAL) {
 lcd.setCursor(0, 0);
 if(!showPID) {
 //if((temperature > TEMP_WO_IRON-5) && (temperature < TEMP_WO_IRON+5)){
                           if(temperature ==TEMP_WO_IRON ){
 heater_mode = OFF;
 lcd.print("     Please     ");
 lcd.setCursor(0, 1);
 lcd.print("  Connect Iron  ");
 if (flash_on < FLASH_ON/LCD_INTERVAL){ // stay on for FLASH_ON ms
 setColor(255, 0, 0);  // red
 flash_on++;
 flash_off = 0;
 }
 else{
 if(flash_off < FLASH_OFF/LCD_INTERVAL){ // stay off for FLASH_OFF ms
 setColor(0, 0, 0);
 flash_off++;
 }
 else flash_on = 0;
 }
 }
 else{
 lcd.write(byte(0));
 lcd.print(' ');
 if(temperature < 98) {
 lcd.print(' ');
 }
 if (int(temperature) % 5 < 3){
 lcd.print(int(temperature / 5) * 5);
 }
 else{
 lcd.print(int(temperature / 5 + 1) * 5);
 }
 lcd.print((char)223);
 lcd.print("C  ");
 printGraph(setpoint, temperature);


 lcd.setCursor(0, 1);
 lcd.print(">");
 lcd.print(" ");
 lcd.print(setpoint, 0);
 lcd.print((char)223);
 lcd.print("C   ");


 if(heater_mode == ON){
 lcd.print(" ON   ");
 lightRGB(setpoint, temperature);
 }
 else{
 lcd.print("OFF   ");
 setColor(255, 255, 255);  // white
 }
 }
 }
 else displayPid();


 last_lcd_update = current_time;
 }
}


// Read Iron temperature
uint16_t readTemp() {
 uint16_t temp = 0;
 //int tempr = thermocouple.readCelsius();
 for (int i = 0; i < 10; i++)
{          int tempr = thermocouple.readCelsius();
 //temp += analogRead(TEMP_PIN);
 temp = tempr;
}
 
 //temp = (EQUATION_A*temp) + EQUATION_B;
 return temp;
}


uint16_t readPot() {
 uint16_t pot = 0;
 
 // Read the potentiometer three times
 pot += analogRead(POT);
 pot += analogRead(POT);
 pot += analogRead(POT);
 
 // Map the value read to the temperature range
 pot = map(pot, 0, 3069, MIN_TEMP, MAX_TEMP);
 if (pot % 5 < 3) return pot / 5 * 5;
 else return (pot / 5 + 1) * 5;
}


// Check if heater start button was pressed
void checkButton() {
    heatButton.listen();
    increaseBrightButton.listen();
    decreaseBrightButton.listen();
    pidButton.listen();


    //Button1
    if(heatButton.onPress()) {
        if (heater_mode == ON) heater_mode = OFF;
        else heater_mode = ON;
    }


     //Button2
    if (decreaseBrightButton.onPress()){
     if (--bright < 1) bright = 10;
     setBrightness(bright);
    }


     //Button3
    if (increaseBrightButton.onPress()){
 if (++bright > 10) bright = 1;
 setBrightness(bright);
    }


     //Button4
    if (pidButton.onPress()){
     if (showPID == OFF){
     showPID = ON;
     }
     else{
     showPID = OFF;
     EEPROM.writeInt(bright_address, bright);
     }
    }
}


// Display PID Constants
void displayPid() {
 lcd.clear();
 lcd.print("P ");
 lcd.print(kp, 2);
 lcd.print(" I ");
 lcd.print(ki, 2);
 lcd.setCursor(0, 1);
 lcd.print("D ");
 lcd.print(kd, 2);


 lcd.print("     ");
 /*if (showAnalog){
 uint16_t temp_analog = 0;
 for (int i=0; i<5; i++){
 temp_analog += analogRead(TEMP_PIN);
 }
 lcd.print(temp_analog/5);
 }
 else lcd.print("    ");
*/}


void setBrightness(int light){
 light = map(light, 1, 10, 245, 10);
   analogWrite(LCD_LED, light);
}


void setColor(int red, int green, int blue)
{
  analogWrite(LED_R, 255-red);
  analogWrite(LED_G, 255-green);
  analogWrite(LED_B, 255-blue);  
}


void lightRGB(double setpoint, double termperature){
 double diff = setpoint - temperature;
 if (diff > RGB_EFECT_MIN) diff = RGB_EFECT_MIN;
 else if (diff < -RGB_EFECT_MAX) diff = -RGB_EFECT_MAX;
 if (diff < 0){
 diff = map(diff, -RGB_EFECT_MAX, 0, 255, 0);
 setColor(diff, 255-diff, 0);
 }
 else{
 diff = map(diff, 0, RGB_EFECT_MIN, 0, 255);
 setColor(0, 255-diff, diff);
 }
}


void printGraph(double setpoint, double termperature){
 double diff = setpoint - temperature;


    if (abs(diff) < 1){
     if (temperature < setpoint){
     lcd.print("   ");
    lcd.write(byte(4));
    lcd.print("   ");
 }
    }
    else if (abs(diff) < 5){
     if (temperature < setpoint){
     lcd.print("  ");
     lcd.write(byte(1));
     lcd.write(byte(2));
     lcd.write(byte(7));
     lcd.print("  ");
    }
    else{
     lcd.print("  ");
 lcd.write(byte(1));
 lcd.write(byte(6));
 lcd.write(byte(7));
 lcd.print("  ");
    }
    }
    else if (abs(diff) < 10){
     if (temperature < setpoint){
     lcd.print(" ");
     lcd.write(byte(1));
     lcd.write(byte(2));
     lcd.write(byte(3));
     lcd.write(byte(6));
     lcd.print("  ");
    }
    else{
     lcd.print("  ");
     lcd.write(byte(2));
 lcd.write(byte(5));
 lcd.write(byte(6));
 lcd.write(byte(7));
 lcd.print(" ");
    }
    }
    else if (abs(diff) < 15){
     if (temperature < setpoint){
     lcd.write(byte(1));
     lcd.write(byte(2));
     lcd.write(byte(3));
     lcd.write(byte(4));
     lcd.print("   ");
    }
    else{
     lcd.print("   ");
     lcd.write(byte(4));
 lcd.write(byte(5));
 lcd.write(byte(6));
 lcd.write(byte(7));
    }
    }
    else if (abs(diff) < 20){
     if (temperature < setpoint){
     lcd.write(byte(2));
     lcd.write(byte(3));
     lcd.write(byte(4));
     lcd.write(byte(4));
     lcd.print("   ");
    }
    else{
     lcd.print("   ");
     lcd.write(byte(4));
 lcd.write(byte(4));
 lcd.write(byte(5));
 lcd.write(byte(6));
    }
    }
    else if (abs(diff) < 25){
     if (temperature < setpoint){
     lcd.write(byte(3));
     lcd.write(byte(4));
     lcd.write(byte(4));
     lcd.write(byte(4));
     lcd.print("   ");
    }
    else{
     lcd.print("   ");
     lcd.write(byte(4));
 lcd.write(byte(4));
 lcd.write(byte(4));
 lcd.write(byte(5));
    }
    }
    else if (abs(diff) < 30){
     if (temperature < setpoint){
     lcd.write(byte(2));
     lcd.write(byte(3));
     lcd.write(byte(4));
     lcd.write(byte(4));
     lcd.write(byte(4));
     lcd.print("  ");
    }
    else{
     lcd.print("  ");
     lcd.write(byte(4));
 lcd.write(byte(4));
 lcd.write(byte(4));
 lcd.write(byte(5));
 lcd.write(byte(6));
    }
    }
    else if (abs(diff) < 35){
     if (temperature < setpoint){
     lcd.write(byte(1));
     lcd.write(byte(2));
     lcd.write(byte(3));
     lcd.write(byte(4));
     lcd.write(byte(4));
     lcd.write(byte(4));
     lcd.print(" ");
    }
    else{
     lcd.print(" ");
     lcd.write(byte(4));
     lcd.write(byte(4));
     lcd.write(byte(4));
     lcd.write(byte(5));
     lcd.write(byte(6));
     lcd.write(byte(7));
    }
    }
    else{
     if (temperature < setpoint){
     lcd.print(" ");
     lcd.write(byte(1));
     lcd.write(byte(2));
     lcd.write(byte(3));
     lcd.write(byte(4));
     lcd.write(byte(4));
     lcd.write(byte(4));
    }
    else{
     lcd.write(byte(4));
     lcd.write(byte(4));
     lcd.write(byte(4));
     lcd.write(byte(5));
     lcd.write(byte(6));
     lcd.write(byte(7));
     lcd.print(" ");
    }
    }
}


// Create degree character
void charSetup() {
 byte therm[8] = {
 0b00100,
 0b01010,
 0b01010,
 0b01010,
 0b01110,
 0b11111,
 0b11111,
 0b01110
 };
 byte bar[7][8] = {
 {0b00000,0b00000,0b00000,0b00000,0b00000,0b00011,0b11011,0b11011},
 {0b00000,0b00000,0b00000,0b00011,0b11011,0b11011,0b11011,0b11011},
 {0b00000,0b00011,0b11011,0b11011,0b11011,0b11011,0b11011,0b11011},
 {0b11011,0b11011,0b11011,0b11011,0b11011,0b11011,0b11011,0b11011},
 {0b00000,0b11000,0b11011,0b11011,0b11011,0b11011,0b11011,0b11011},
 {0b00000,0b00000,0b00000,0b11000,0b11011,0b11011,0b11011,0b11011},
 {0b00000,0b00000,0b00000,0b00000,0b00000,0b11000,0b11011,0b11011}
 };
 lcd.createChar(0, therm);
 lcd.createChar(1, bar[0]);
 lcd.createChar(2, bar[1]);
 lcd.createChar(3, bar[2]);
 lcd.createChar(4, bar[3]);
 lcd.createChar(5, bar[4]);
 lcd.createChar(6, bar[5]);
 lcd.createChar(7, bar[6]);
}

billtsig

Μηνύματα : 97
Εγγραφή : 16/11/2012
Τόπος : Αθήνα

Επιστροφή στην κορυφή Πήγαινε κάτω

Μια μικρή βοήθεια σε arduino! Empty Απ: Μια μικρή βοήθεια σε arduino!

Δημοσίευση από spirakos Κυρ Μάης 22, 2016 10:11 pm

Αν και δε μπορω να σε βοηθησω πιστευω θα ηταν καλυτερα να εβαζες μονο το μερος ή τα μερη του κωδικα που υπαρχει το προβλημα
Τα υπολοιπα απο τους ειδικοτερους
spirakos
spirakos

Μηνύματα : 1121
Εγγραφή : 23/10/2012
Ηλικία : 29
Τόπος : Κερατσίνι

Επιστροφή στην κορυφή Πήγαινε κάτω

Μια μικρή βοήθεια σε arduino! Empty Απ: Μια μικρή βοήθεια σε arduino!

Δημοσίευση από billtsig Κυρ Μάης 22, 2016 10:29 pm

καλησπέρα σπύρο
σε ευχαριστώ για την πρόθεση σου να με βοηθήσεις (όπως με είχες βοηθήσει στα προβλήματα μου με τον λαμπάτο μου) να είσαι καλά

τελικά η λύση βρέθηκε έπρεπε να βάλω ένα delay στον κώδικα μου το σωστό είναι έτσι

λάθος:
Κώδικας:
// Read Iron temperature
uint16_t readTemp() {
   uint16_t temp = 0;
 //int tempr = thermocouple.readCelsius();
   for (int i = 0; i < 10; i++)
{          int tempr = thermocouple.readCelsius();
      //temp += analogRead(TEMP_PIN);
    temp = tempr;
}
   
   //temp = (EQUATION_A*temp) + EQUATION_B;
   return temp;
}

σωστό
Κώδικας:
// Read Iron temperaturedouble readTemp() {
    double temp = thermocouple.readCelsius();
    delay(220);
    return temp; }

billtsig

Μηνύματα : 97
Εγγραφή : 16/11/2012
Τόπος : Αθήνα

Επιστροφή στην κορυφή Πήγαινε κάτω

Μια μικρή βοήθεια σε arduino! Empty Απ: Μια μικρή βοήθεια σε arduino!

Δημοσίευση από spirakos Δευ Μάης 23, 2016 9:31 am

Μια χαρα!
Αληθεια εβγαλες ακρη με το βομβο?
spirakos
spirakos

Μηνύματα : 1121
Εγγραφή : 23/10/2012
Ηλικία : 29
Τόπος : Κερατσίνι

Επιστροφή στην κορυφή Πήγαινε κάτω

Μια μικρή βοήθεια σε arduino! Empty Απ: Μια μικρή βοήθεια σε arduino!

Δημοσίευση από billtsig Τρι Μάης 24, 2016 1:15 am

καλησπέρα και πάλι

με τον βόμβο παιδευτικά αρκετά μέχρι που αναγκαστικά να κατασκευάσω τις πλακέτες του Γιώργου , εκεί φάνηκε κατευθείαν η επιτυχία μιας και ο βόμβος ήταν ελάχιστος μόλις μπήκαν όλα σε κουτί και με σωστές γειώσεις ο ενισχυτής έπαιξε τέλεια χωρίς βόμβο

το μόνο πρόβλημα που έχω είναι πως έχω ένα μικρό φύσημα όταν ανοίγω το voliume τέρμα και ΔΕΝ έχω συνδεδεμένα rca έψαξα και βρήκα πως είναι από την αντίσταση εισόδου τον νου meter αλλά δυστυχώς δεν βρήκα χρόνο να ασχοληθώ και το αφίσα έτσι μιας και με είσοδο παίζει χωρίς θόρυβο ακόμα και στο τέρμα με το cd σταματημένο πχ

billtsig

Μηνύματα : 97
Εγγραφή : 16/11/2012
Τόπος : Αθήνα

Επιστροφή στην κορυφή Πήγαινε κάτω

Επιστροφή στην κορυφή

- Παρόμοια θέματα

 
Δικαιώματα σας στην κατηγορία αυτή
Δεν μπορείτε να απαντήσετε στα Θέματα αυτής της Δ.Συζήτησης