I have been programming my atmega1284p using my raspberry pi 400 to do simple things like turn on LEDs, run motors etc. I'm quietly putting together an autonomous 4 wheeled robot that besides being able to move under its own power, will also use sensors to detect the environment. At the moment I have accomplished the 4 wheeled self propelled bit with no problem. However, I'm trying to sense temperatures using the DS18B20. I have written some code so that the temperature is displayed on a 20x4 LCD and it works perfect when I test it on the Arduino Uno. Then when I port the hex software over to the atmega1284p, it just doesn't recognise the ds18b20. I've been trying to fix this for weeks, probably months, and this is my last hope, that someone here has had a similar problem. So all thoughts/ideas considered (I've tried a few). Pete
The first thing to do is write the most simple, minimal possible sketch to test the DS18B20. This should simply print the reading to Serial monitor once a second. The sketch should not contain any code for motors or LCD.
Verify that the sketch works as expected on the Uno.
Check whether the sketch works on the ATmega1284P.
After that, come back here and, in a reply, give us:
- The full sketch
- Precise instructions for how we can install any libraries the sketch uses
- A precise description of how you have the DS18B20 connected to your ATmega1284P
- Precise instructions for how we can install support for the ATmega1284P to the Arduino IDE
- The exact selections from the Arduino IDE's Tools > Board menu, as well as any other custom board menus of the ATmega1284P board
Hi,
Thanks for your response, couple of comments :-
- I have already written a sketch to just display the temperature once a second on the serial monitor, without any other code being involved. – this worked using the Arduino, but I can’t run this on the atmega1284p because it hasn’t got a serial monitor.
- I converted the out put in (1) above to display on a 20x4 LCD, and using the Arduino Uno, this works just fine as well.
- I took the hex from (2) above, connected the DS18B20 and LCD to the atmega1284p and loaded the hex onto the atmega1284p using the raspberry pi 400 “linuxgpio” programmer (as I usually do). The hex loads OK, and then runs. I get the characters being displayed on the LCD, but the DS18B20 does not get recognised as I get “no more addresses found” message.
- The difficulty in testing in this way is that to run the program using the Arduino Uno, it has (a) a different set of pins to the atmega1284p, and (b) it uses the ArduinISP programmer instead of the “linuxgpio”. So I think the issue lies between these 2 facts. I’ve tried to emulate the pins between the Arduino and the atmega1284p by using pin 0 for the ds18b20, pins 1, 2 and 3 for RS, RW, and E on the LCD and pins 4, 5, 6, & 7 for the D4, D5, D6, & D7 pins on the LCD (in 4 bit mode). In theory these pins should match up both the Arduino AND the atmega1284p. This configuration works just fine using the Arduino, DS18B20 and the 20x4 LCD. So, thinking about this, the differences are :-
(i). Different boards selected in the Arduino IDE ( Arduino as opposed to Mighty-Core Atmega1284).
(ii). Different programmers – ArduinoISP in the Arduino IDE and “linuxgpio” using avrdude.
I can send the code I’m using if you like, but I think the issue is with the board and/or programmer ?
Cheers,
Pete
After investigating with further tests, it seems that Arduino IDE running on a Raspberry Pi either (1) does not generate the correct hex code to display (on an lcd), (2) the raspberry pi does not load the hex code correctly up to a stand alone atmega1284p. I'm tempted to think it's the latter, I just can't believe there's a bug in generating hex code with Arduino IDE. So, with that in mind, when compiling the code I use the Mighty Core atmega1284 as the board, and then upload from the raspberry pi to the atmega1284p using the reset, mosi, miso and sclk pins via avrdude e.g. avrdude -pm1284p -clinuxgpio -v -U flash:w:ds18b20:i
Does anyone think that there's something wrong with the linuxgpio setup maybe ?
I've tried the same with the DHT11, and get the same problem. Both work via the arduino, but not when loaded to the atmega1284p.
Should I dump the linuxgpio and use an AVRISP maybe ?
Answers on a postcard to......
Can you create a short code for both methods, and compare the two files?
Just "empty" sketches even, with no code in setup() and loop().
Well, I think we're making (a little) progress. I created a very simple blink program and uploaded to the atmega1284p using the arduino uno in "arduino as isp" mode, and that all seems fine.
Then tried my ds18b20 program again, and it appears to upload OK, and indeed characters are displayed on my 20x4 LCD as I would expect them, but, it doesn't appear to want to recognise the ds18b20. So here's my program -
+++++++++++++++++++++++++++++++++++++++++++++++++++
#include<OneWire.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(0, 1, 2, 4, 5, 6, 7);
OneWire ds(3);
void setup(void)
{
lcd.begin(20, 4);
lcd.setCursor(0, 0);
lcd.print("Temperatures in C/F ");
lcd.setCursor(0, 1);
lcd.print("=================== ");
}
void loop(void)
{
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if (!ds.search(addr))
{
lcd.setCursor(0, 2);
lcd.print("*No Addresses found*");
ds.reset_search();
delay(1000);
return;
}
if (OneWire::crc8(addr, 7) != addr[7])
{
return;
}
// the first ROM byte indicates which chip
switch (addr[0])
{
case 0x28:
type_s = 0;
break;
default:
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();
}
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s)
{
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10)
{
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
}
else
{
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
lcd.setCursor(0, 2);
for (byte a = 0; a < 16; ++a) lcd.print(" ");
lcd.setCursor(0, 3);
for (byte a = 0; a < 16; ++a) lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print(celsius); lcd.print(" "); lcd.write(0xDF); lcd.print("C");
lcd.setCursor(0, 3);
lcd.print(fahrenheit); lcd.print(" "); lcd.write(0xDF); lcd.print("F");
delay(500);
}
++++++++++++++++++++++++++++++++++++++++++++++++
I have arduino pins 10, 11, 12 & 13 connected to the atmega1284p reset, mosi, miso and sclk respectively. My board is set to the Migh[ty]Core atmega1284p, 16Mhz external crystal, and programmer is set to Arduino as ISP (I have previously loaded the ArduinoISP to the Arduino Uno).
So if anyone spots anything obvious, please let me know
This pinout?
So OneWire ds(3); is connected to PB3?
I'll do some reading, see if there is anything funny about onewire on that particular pin.
• AIN1/OC0A/PCINT11, Bit 3
AIN1, Analog Comparator Negative input. This pin is directly connected to the negative input of the Analog Comparator.
OC0A, Output Compare Match A output: The PB3 pin can serve as an external output for the Timer/Counter0 Output Compare. The pin has to be configured as an output (DDB3 set “one”) to serve this function. The OC0A pin is also the output pin for the PWM mode timer function.
PCINT11, Pin Change Interrupt source 11: The PB3 pin can serve as an external interrupt source.
That's the correct pinout I'm using
To be on the safe side, I've now put the ds18b20 on PD0 (pin 8), and the LCD on (7, 10, 11, 12, 13, 14, 15), that's PD1 to PD7.
Exactly the same results. Really baffling.
That should be LCD on (9, 10, 11, 12, 13, 14, 15) PD1 to PD7
I've not used onewire for anything; sorry, I don't have anything else to offer.
No worries Crossroads, I've given up using Arduino to generate the hex file, I'm thinking I'm probably better off using straight forward C or C++ using the GEANY IDE. Compile and link with AVR-GCC/G++ and then load with avrdude. Let y'all know how I get on....
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.