Digistump Forums
The Digispark => Digispark (Original) Support => Topic started by: atrueresistance on January 19, 2013, 01:38:59 pm
-
Hello I'm currently using windows 7 64bit. For programming my Digispark. I have some questions however on the DigiUSB library. When I upload the Echo example and then use monitor.exe to view and send commands this works flawlessly. However If I use the program I'm converting from Arduino to Digispark I get a nasty No DigiUSB Device Detected. Here is the code.
#include
#include
#define RELAY_PIN 1
#define ONE_WIRE_BUS 5
//#include // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos
//#include // for LCD w/ GPIO MODIFIED for the ATtiny85
#define GPIO_ADDR 0x27
#define DS18B20_ID 0x28
OneWire oneWire(ONE_WIRE_BUS);
OneWire ds(ONE_WIRE_BUS);
//LiquidCrystal_I2C lcd(GPIO_ADDR,16,2); // set address & 16 chars / 2 lines
void setup(void)
{
pinMode(RELAY_PIN, OUTPUT);
DigiUSB.begin(); // open DigiUSB
//TinyWireM.begin(); // initialize I2C lib - comment this out to use with standard arduinos
//lcd.init(); // initialize the lcd
//lcd.backlight(); // Print a message to the LCD.
//lcd.print("Digispark!");
}
void loop(void)
{
float target = 63;
float temp = 62; //getTemperature(); need to debug this function
if(temp >= target){
digitalWrite(RELAY_PIN, LOW);
DigiUSB.println("Heater Off");
}
else if(temp < target){
digitalWrite(RELAY_PIN, HIGH);
DigiUSB.println("Heater On");
}
DigiUSB.println(temp);
delay(6000);
}
float getTemperature(){
float temp;
byte i;
byte present = 0;
byte data[12];
byte addr[8];
//find a device
if (!ds.search(addr)) {
ds.reset_search();
return 0.00;
}
if (OneWire::crc8( addr, 7) != addr[7]) {
return 0.01;
}
if (addr[0] != DS18B20_ID) {
return 0.02;
}
ds.reset();
ds.select(addr);
// Start conversion
ds.write(0x44, 1);
// Wait some time...
delay(850);
present = ds.reset();
ds.select(addr);
// Issue Read scratchpad command
ds.write(0xBE);
// Receive 9 bytes
for ( i = 0; i < 9; i++) {
data = ds.read();
}
ds.reset_search(); //reset the only 1 device on
// Calculate temperature value
temp = ( (data[1] << 8) + data[0] )*0.0625;
temp = (temp * 9/5)+32;
return temp;
}
I'm a little confused as to why the Echo program works, and mine doesn't. If someone could enlighten me? Please.
-
Seems as I forgot DigiUSB.refresh(); I have found a different problem now. It seems to have an overflow somewhere. Could this be the Monitor.exe? http://imgur.com/NtmwGy9
-
This overflow is occurring in the library I believe - we\'re working on why this occurs sometimes and not others - a good alternative for now is to only send data over USB when it is requested - see the DigiScope example for one approach to this - basically it waits until anything is sent to it and then sends a reading
-
This overflow is occurring in the library I believe - we\'re working on why this occurs sometimes and not others - a good alternative for now is to only send data over USB when it is requested - see the DigiScope example for one approach to this - basically it waits until anything is sent to it and then sends a reading
Has this been fixed? If so, from which version? Thanks.