Why does ATTiny167 disconnect?

  1. When I connect a DIgistump (ATTiny85 breakout board) to my PCs USB it connects and stays on. If I do the same with a Digispark Pro (ATTiny167) it connects and disconnects after 3 seconds.

  2. When I try to upload a sketch I get “avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)”. Since ATTiny167 runs Micronucleus as bootloader it should prompt for a device. It is impossible to connect the ATTiny just in time for the uploader to detect it.

Processing attiny167 (platform: atmelavr; board: attiny167; framework: arduino)
-----------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/attiny167.html
PLATFORM: Atmel AVR (3.4.0) > Generic ATtiny167
HARDWARE: ATTINY167 8MHz, 512B RAM, 16KB Flash
PACKAGES:
 - framework-arduino-avr-attiny 1.5.2
 - tool-avrdude 1.60300.200527 (6.3.0)
 - toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 14 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Adafruit SSD1306> 2.5.1
|   |-- <Adafruit GFX Library> 1.10.13
|   |   |-- <Adafruit BusIO> 1.11.2
|   |   |   |-- <Wire> 2.0.0
|   |   |   |-- <SPI> 2.0.0
|   |   |-- <SPI> 2.0.0
|   |   |-- <Wire> 2.0.0
|   |-- <SPI> 2.0.0
|   |-- <Wire> 2.0.0
|-- <Adafruit GFX Library> 1.10.13
|   |-- <Adafruit BusIO> 1.11.2
|   |   |-- <Wire> 2.0.0
|   |   |-- <SPI> 2.0.0
|   |-- <SPI> 2.0.0
|   |-- <Wire> 2.0.0
|-- <Adafruit BusIO> 1.11.2
|   |-- <Wire> 2.0.0
|   |-- <SPI> 2.0.0
|-- <OneWire> 2.3.6
|-- <DallasTemperature> 3.9.1
|   |-- <OneWire> 2.3.6
Building in release mode
Checking size .pio\build\attiny167\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=====     ]  49.8% (used 255 bytes from 512 bytes)
Flash: [========  ]  84.8% (used 13886 bytes from 16384 bytes)
Configuring upload protocol...
AVAILABLE: usbtiny
CURRENT: upload_protocol = usbtiny
Looking for upload port...
Uploading .pio\build\attiny167\firmware.hex
avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)

avrdude done.  Thank you.

*** [upload] Error 1
=============================== [FAILED] Took 5.75 seconds ======

Please file an issue in GitHub - platformio/platform-atmelavr: Atmel AVR: development platform for PlatformIO since the board definition is there.

I found somewhere an example where they had included “upload_protocol = micronucleus” in PIO.ini and the upload worked but when I connect the ATTiny167 it still disconnects after 3 seconds.

My bad – I just saw you’re using board = attiny167. You should be using board = digispark-pro instead.

maxgerhardt
I changed to digispark-pro and had to delete a few built libraries but it works now. The reason I jumped over to the ATTiny167 was to see if the problem with the OLED display showing 25 degrees for both sensors would show here and it still does. The problem has nothing to do with the esp32 where I first saw the problem… I’ve been thinking if it has something to do with conversion from float to char*. If I bricked the sensors they would probably show nothing or something other than 25.

Code:

#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SSD1306xLED.h>
#define ONEWIRE_BUS 6

const int DISP_COLS = 128;
const int DISP_ROWS = 64;
const int DISP_RESET = -1;
const char DISP_ADDR = 0x3C;
const char SYMBOL = 176;        // degree sign
const char LET_C = 67;          // letter C
float leftC, rightC;
char tArray[5];

DeviceAddress MagLeft =  {0x28, 0x4E, 0xB0, 0x75, 0xD0, 0x01, 0x3C, 0xDE};
DeviceAddress MagRight = {0x28, 0x9E, 0x9D, 0x75, 0xD0, 0x01, 0x3C, 0x0E};

OneWire oneWire(ONEWIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup()
{
 // Serial.begin(9600);
 sensors.begin();
 sensors.setResolution(MagLeft, 9);
 sensors.setResolution(MagRight, 9);
 delay(500);

 SSD1306.ssd1306_init();
 SSD1306.ssd1306_fillscreen(0x00);
 SSD1306.ssd1306_setpos(0, 0);  
 SSD1306.ssd1306_string_font6x8((char *)"Mag temps");  
}

void loop()
{
 leftC = sensors.getTempC(MagLeft);
 rightC = sensors.getTempC(MagRight);

 dtostrf(leftC, 4, 1, tArray);
 //itoa(leftC, tArray,10);          // int > char*  
 SSD1306.ssd1306_setpos(0, 2);
 SSD1306.ssd1306_string_font6x8((char *)"Left:  ");
 SSD1306.ssd1306_string_font6x8(tArray);
 SSD1306.ssd1306_char_font6x8(SYMBOL);
 SSD1306.ssd1306_char_font6x8(LET_C);  

 dtostrf(rightC, 4, 1, tArray);
 //itoa(rightC, tArray,10);          // int > char*  
 SSD1306.ssd1306_setpos(0, 3);
 SSD1306.ssd1306_string_font6x8((char *)"Right: ");
 SSD1306.ssd1306_string_font6x8(tArray);
 SSD1306.ssd1306_char_font6x8(SYMBOL);
 SSD1306.ssd1306_char_font6x8(LET_C);

 //Serial.print("L: ");
 //Serial.println(tArray);
 //Serial.print("R: ");
 //Serial.println(rightC);    
}

Do you have a cheap logic analyzer? Salae logic analyzer clones are just ~10€ (e.g. “AZDelivery Logic Analyzer 8 CH”), you can plug them into the OneWire bus and see the data. Then there’s no guessing around on what conversion went wrong, if the logic decoder shows that the sensor sends the data for “25.0°C”, then the fault is localized exactly there.

OK, I just ordered a AZDelivery Logic Analyzer 8 CH and it’ll arrive in a few days. In the meantime I downloaded Saleae Logic Analyzer version 1.2.18. Looked like it was free and I hope it’s the right version.