Ho cambiato l'hardware perche il 2009 era, secondo me, sprecato.
Il 595 e' relativo all'utilizzo nella zona breadboard dello xino di un 74hc595 per la gestione 2-wire del lcd. Per l'oscillatore ho utilizzato 2 capacita' da 8,2 pf avendo terminate quelle da 22pf.
Rispetto al "prototipo" con bb ora tutto e' molto piu compatto
Lo sketch e' rimasto pressoche identico (ide 1.00), la mcu e' un atmega8 con optiboot: Binary sketch size: 6708 bytes (of a 7680 byte maximum). Non e' rimasto molto spazio ma c'e' sicuramente qualcosa da ""rosicchiare": alle brutte si monta un 328p. Con la 023 ho circa 4-500 bytes in piu'...Non ricordo pero' perche' ho utilizzato la 1.0
Codice: Seleziona tutto
#include <OneWire.h>
#include <Wire.h>
#include <LiquidCrystal_SR.h>
LiquidCrystal_SR lcd(7,8,TWO_WIRE);
// | | + enable
// | \-- Clock Pin
// \---- Data/Enable Pin
///#define CONTRAST_PIN 9
///#define CONTRAST 90
// DS18S20 Temperature chip i/o
OneWire ds(10); // on pin 10
void setup()
{
///pinMode(CONTRAST_PIN, OUTPUT);
///analogWrite (CONTRAST_PIN, CONTRAST);
// initialize inputs/outputs
// start serial port
Serial.begin(9600);
lcd.begin(24,2); // initialize the lcd
lcd.home (); // go home
lcd.print("wait...");
delay(1000);
lcd.home ();
}
void loop()
{
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
byte i;
byte present = 0;
byte data[12];
byte addr[8];
char temp[] = { "temp.:" };
if ( !ds.search(addr)) {
Serial.println();
ds.reset_search();
delay(30000);
lcd.clear();
return;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.print("CRC err\n");
return;
}
Serial.print("S:");
if ( addr[0] == 0x10) {
Serial.print("DS18S20 ");
}
else if ( addr[0] == 0x28) {
Serial.print("DS18B20 ");
}
else {
Serial.print("err: 0x");
Serial.println(addr[0],HEX);
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
Whole = Tc_100 / 100; // separate off the whole and fractional portions
Fract = Tc_100 % 100;
Serial.print(temp);
lcd.print(temp);
if (SignBit) // If its negative
{
Serial.print("-");
lcd.print("-");
}
Serial.print(Whole);
lcd.print(Whole);
Serial.print(".");
lcd.print(".");
if (Fract < 10)
{
Serial.print("0");
lcd.print("0");
}
Serial.print(Fract);
lcd.print(Fract);
Serial.println();
lcd.setCursor ( 0,2 ); // go to position
}
Questa e' la configurazione per lo xino8 con optiboot da inserire in boards.txt
Codice: Seleziona tutto
atmega8o.name=Arduino 2009 (ATmega8) OPTIBOOT
atmega8o.upload.protocol=arduino
atmega8o.upload.maximum_size=7680
atmega8o.upload.speed=115200
atmega8o.bootloader.low_fuses=0xBF
atmega8o.bootloader.high_fuses=0xdc
atmega8o.bootloader.path=optiboot
atmega8o.bootloader.file=optiboot_atmega8.hex
atmega8o.bootloader.unlock_bits=0x3F
atmega8o.bootloader.lock_bits=0x0F
atmega8o.build.mcu=atmega8
atmega8o.build.f_cpu=16000000L
atmega8o.build.core=arduino
atmega8o.build.variant=standard