Ciao a tutti,
ho un problema con questo codice per Arduino nano (copia cinese della marca ELEGOO).
all'inizio funzionava, ma poi ho fatto una modifica in modo che se la tensione va al di sotto di 10V, si attivi il pin 2...
Da quando ho provato a caricare il codice modificato, l'arduino continua a dare l'errore:
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "/Users/xxxxxxx/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
User configuration file is "/Users/xxxxxxxx/.avrduderc"
User configuration file does not exist or is not a regular file, skipping
Using Port : /dev/cu.usbserial-14210
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
avrdude done. Thank you.
Caricamento non riuscito: errore durante il caricamento: exit status 1
questo è il codice (non fate caso alla parte del display, perchè alla fine mi si è bruciato il display e quindi ho scelto di visualizzare i volt da monitor seriale)
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // Larghezza del display OLED
#define SCREEN_HEIGHT 64 // Altezza del display OLED
#define OLED_RESET -1 // Pin di reset del display (non utilizzato)
#define LED_PIN 2 // Pin del LED
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int analogInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // Inserire il valore esatto della resistenza R1 (100K)
float R2 = 10000.0; // Inserire il valore esatto della resistenza R2 (10K)
int value = 0;
void setup() {
pinMode(analogInput, INPUT);
pinMode(LED_PIN, OUTPUT); // Imposta il pin del LED come output
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Indirizzo I2C del display
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("VOLTMETRO");
Serial.begin(9600);
}
void loop() {
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0;
// Inserire al posto di 5.0V l'uscita in volt tra i pin 5V e GND del vostro Arduino
vin = vout / (R2 / (R1 + R2));
if (vin < 0.09) {
vin = 0.0;
}
//display.setCursor(0, 16);
//display.print("v ");
//display.print(vin);
//display.display();
Serial.print("v ");
Serial.println(vin);
if (vin < 10.0) {
digitalWrite(LED_PIN, HIGH); // Accende il LED
} else {
digitalWrite(LED_PIN, LOW); // Spegne il LED
}
delay(10000);
}
Mi viene il dubbio che dal partitore di tensione che ho creato sulla breadboard sia passata qualche tensione che ha danneggiato prima il display e adesso l'arduino nano...
lo schema di collegamento delle resistenze e arduino l'ho preso da quì: 59. Arduino voltmetro digitale con display da 0 a 30V - PROGETTI ARDUINO
Come batteria da cui misurare il volt ho usato una batteria al piombo da 12v 7ah (al momento delle prove, la tensione della batteria era di circa 10,5 volt)
Avete qualche idea?
Grazie mille ![]()