Digistump Forums
The Digispark => Digispark Projects => Topic started by: plexer on October 10, 2015, 08:31:01 am
-
So I've put together some code using a waterproof ds18b20 sensor and the digiled for feedback.
If the temp is above my setpoint it goes red, below it goes blue and normal it's green.
Code is below the weird thing is that it works perfectly if plugged in to my laptop for power but if I plug it in to an anker 5 port usb charger it only displays blue any idea why that may be?
Thanks.
Ben
// Based on NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license
#include <Adafruit_NeoPixel.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Which pin on the Digispark is connected to the DigiLED?
#define PIN 5
// How many DigiLEDs are attached to the Digispark?
#define NUMPIXELS 1
// Data wire is plugged into pin 12 on the Arduino
#define ONE_WIRE_BUS 12
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// For the WS2812B type through hole LED used by the DigiLED, NEO_RGB + NEO_KHZ800 is the correct data format
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
int delayval = 10000; // delay for 10 seconds
//float
int temp_setpoint = 26; // ideal temperature is this
void setup()
{
// Start up the library
sensors.begin();
pixels.begin(); // This initializes the NeoPixel library.
pixels.show(); // Initialize all pixels to 'off'
}
void loop()
{
//read temperature from 1 wire device
sensors.requestTemperatures();
//float
int read_temp = sensors.getTempCByIndex(0);
if (read_temp < (temp_setpoint - 2)) //if temp is less than 25 make led blue
{
// blue
//Serial.print("Blue");
pixels.setPixelColor(0, pixels.Color(0, 0, 255)); //blue
pixels.show();
delay(delayval);
}
else if (read_temp > (temp_setpoint + 2)) //if temp is higher than 27 make led red
{
// red
//Serial.print("Red");
pixels.setPixelColor(0, pixels.Color(255, 0, 0)); //red
pixels.show();
delay(delayval);
}
else //temp is ok so make it green
{
// green
//Serial.print("Green");
pixels.setPixelColor(0, pixels.Color(0, 255, 0)); //green
pixels.show();
delay(delayval);
}
}
-
Is the ds18b20 receiving Vdd from the power supply(3-wire connection), or are you relying on the parasitic capabilities of the device for power (2-wire connection)?
-
It's using parasitic.
Ben
-
Just converted it to 3 wire but same result it's just weird.
Ben
-
Plugged in to a mobile phone charger it always stays blue.
Plugged in to the laptop it goes green, red if I warm the sensor and blue if I cool it which is the expected behaviour.
I have the 1 wire sensor data line connected to pin12 on the pro, I am using a free gnd connection once the digiled shield is inserted and I'm pulling vcc from the pro.
Ben
-
Which is why it's not working because the pin I'm using to power it only supplys 5v when powered by usb or vin :)
Let me go check.
Ben
-
Or not as it's being powered by usb.
Doh!
-
Have you read this page: https://developer.mbed.org/users/snatch59/notebook/onewirecrc/
Seems you might need to fool with the pull-up on the data line. Maybe set the pin to use the internal pullup or provision your circuit with an external pullup.
-
Would definitely look at using an external pull up resistor. I've experienced read errors when the pull up was too high a value. Been using about 2k.
-
Thinking further on this it could be the value of the resistor that I'm using it's just some I had laying around and is not even 4.7k.
Ben
-
Hey plexer, when you get this working can you report back? I'm working on some similar projects and it would be nice to see what you come up with.