I have wired up an ATTiny85 Digispark board with two temp sensors and an OLED display. I’ve tried to do it by the book and both sensors show -127 which could mean different things I suppose other than it is something wrong. I’ve seen sites showing wiring which is propably wrong for OneWire but I can’t be sure, this one Wiring The DS18B20 1-Wire Temperature Sensor | 14core.com shows a connection of 5V to Vdd on the sensors.
#include <Arduino.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <SSD1306xLED.h>
#include <font6x8.h>
#include <font8x16.h>
#define ONEWIRE_BUS 4
float leftC, rightC; // Temperature in Celsius
char tArr[4];
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()
{
_delay_ms(40);
SSD1306.ssd1306_init();
sensors.begin();
sensors.setResolution(MagLeft, 9);
sensors.setResolution(MagRight, 9);
}
void loop()
{
SSD1306.ssd1306_fillscreen(0);
leftC = int(sensors.getTempC(MagLeft));
rightC = int(sensors.getTempC(MagRight));
SSD1306.ssd1306_setpos(0, 1);
itoa(leftC, tArr, 10); // int > char*
SSD1306.ssd1306_string_font6x8((char *)"Left mag: ");
SSD1306.ssd1306_string_font6x8(tArr);
SSD1306.ssd1306_setpos(0, 3);
itoa(rightC, tArr, 10); // int > char*
SSD1306.ssd1306_string_font6x8((char *)"Right mag: ");
SSD1306.ssd1306_string_font6x8(tArr);
// SSD1306.ssd1306_char_f8x16(0, 4, (char*)"ABCDEFGHI");
_delay_ms(3000);
}