Hi. I'm just a beginner. I can't get the ds18b20 to work. I wrote the code as described in the help. Besides, I watched the video here. https://www.youtube.com/watch?v=iBojUPEJO2g
And that's where it works. But I don't. If I use ReadDigitalTemp, the display shows 0.0625. And if readtemp, then the display is 128. Here is my code. What am I doing wrong?
I've seen it. Moreover, I copied the code from there for mega328. I couldn't get him to work either.
And I would like to understand what is wrong with my code?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I2C is working. If I output any text, it is displayed correctly on the screen. ReadDigitalTemp displays a value of 0.0625. A 4.7K resistor is present, according to the datasheet. I have not used another compiler. Which compiler should I try?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can take a photo if necessary, but I'm not sure if it will help. There's a bunch of wires with a minimum board for the atmega8. A 4.7k resistor is connected between the red and yellow wires. I've attached a drawing. This sensor works correctly when connected to the arduino.
Your code returns 65535.
I made a circuit with an analog LM335 sensor with output to an LED display. Everything is working as it should. But I can't get the ds18b20 to work.
I took the code from here.
c:\GCstudio\gcbasic\demos\Temperature_Sensor_Solutions\DS18B20_Sensor_Solutions\Sensor_ROM_Read_to_LCD\DS18B20_ROM_Read_to_LCD_1Wire_supporting_LCD_IO_10_mega328p.gcb
Just changed atmega328 to atmega8. I have installed the Proteus Free Trial.
You gave me an idea. I configured the atmega8 to run at 16 MHz. And, unexpectedly, the sensor showed the correct temperature. After that, I tried an 8 MHz configuration. At this frequency, the sensor also shows the correct temperature. Then I reduced the frequency to 4 MHz and got a result of 0.0625. The atmega8 default configuration runs at 1 MHz.
So, the conclusion is that the code doesn't work at low frequencies.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
And yes, if you explicitly specify the frequency as 1MHz in the original code, it also works. I didn't know that if you don't explicitly specify the frequency, it takes the highest possible value.
Last edit: Jury 2026-06-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I do not have a device here, but, I see that that the library has been optimised for speed.
Add the following to your program. This will be called replacing the existing the library sub routine.
This is restores the time delays.
Test please.
SubDS18B20DeviceRead' This routine makes available a variable called DSdata' DSdata is the raw data value from the sensorwait250ms' Not really needed but left in just in case ***MasterRST' Reset ds18b20PPulse' Request a presence pulsewait1msOWoutSkipRom' Bypass ds18b20 serial number readwait1msOWoutConvertT' Instruct ds18b20 to begin temperature conversion to digitalDodirDQoutSetDQOffwait4usDirDQInwait7usIfDQ=1ThenExitDowait60us'minimum 60 us time slots between readsLoopMasterRSTPPulsewait1msOWoutSkipRom' Bypass ds18b20 serial number readwait1msOWoutReadScratch' Read temperature from db18b20wait1msOwin' Receive temperature low byte from db18b20DSdata=RxData' First byte is low bytewait1msOwin' Receive temperature high byte from db18b20DSdata_H=RxData' Second byte is high byte (auto combined into 16 bit word)endsub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi. I'm just a beginner. I can't get the ds18b20 to work. I wrote the code as described in the help. Besides, I watched the video here. https://www.youtube.com/watch?v=iBojUPEJO2g
And that's where it works. But I don't. If I use ReadDigitalTemp, the display shows 0.0625. And if readtemp, then the display is 128. Here is my code. What am I doing wrong?
https://github.com/Anobium/Great-Cow-BASIC-Demonstration-Sources/tree/master/Temperature_Sensor_Solutions/DS18B20_Sensor_Solutions/Sensor_to_Software_Serial_Terminal
There are many working demos on GitHub.
I've seen it. Moreover, I copied the code from there for mega328. I couldn't get him to work either.
And I would like to understand what is wrong with my code?
What is PC3? How about:
#define DQ PortC.3Last edit: Roger Jönsson 2026-06-15
@Jury
Post the ASM file being generated. I want to see the version of the compiler in use.
So, you have the I2C LCD working. That is good.
PC3 should work as the port. As this resolves to PORTC.3
A quick search of the demos shows many published/verified demos.
Let me see the ASM.
My GCBasic\demos folder looks like this
Last edit: Jury 2026-06-16
Re the empty(ish) demo folder. Download and install the Demo Pack shown on GCSTUDIO startup application.
ASM looks ok in terms of updates. Yes, there are later builds but this is the recent general release build.
Things that you can verify for me.
LCD shows strings and values. This tells me the I2C hardware is working.
Do a operation. What DSData return?
You have a 4k7 pullup from the Portc.3 to 5v0 as per the device datasheet.
There are no errors shown when compiling.
Has this circuit worked with another compiler?
Things I do know.
Your code works in a Simulator.
There are many working demos. But, this is not to say that in this specific use case there is not an error. :-)
Evan
I2C is working. If I output any text, it is displayed correctly on the screen. ReadDigitalTemp displays a value of 0.0625. A 4.7K resistor is present, according to the datasheet. I have not used another compiler. Which compiler should I try?
Was not recommending another compiler. This is a very good toolchange.
As you are get 0.0625 back this means that the values obtained by the read routines equate to 1
And, that would be very cold.
What did DSData return on the LCD?
Check you have that 4k7 connected correctly. Post a foto of the setup.
Minimum code to read the sensor would be. This should return the raw value. Depends what this returned will determine the next step.
I can take a photo if necessary, but I'm not sure if it will help. There's a bunch of wires with a minimum board for the atmega8. A 4.7k resistor is connected between the red and yellow wires. I've attached a drawing. This sensor works correctly when connected to the arduino.
Your code returns 65535.
Arduino is another compiler. That is good to know it works with this setup.
But, with this exact setup, these connections/pinout?
This is puzzling. As it works on simulation.
I made a circuit with an analog LM335 sensor with output to an LED display. Everything is working as it should. But I can't get the ds18b20 to work.
I took the code from here.
c:\GCstudio\gcbasic\demos\Temperature_Sensor_Solutions\DS18B20_Sensor_Solutions\Sensor_ROM_Read_to_LCD\DS18B20_ROM_Read_to_LCD_1Wire_supporting_LCD_IO_10_mega328p.gcb
Just changed atmega328 to atmega8. I have installed the Proteus Free Trial.
Got this.
Last edit: Jury 2026-06-16
OK.
What did this return? DSDATA specificially
Do forever
Loop
that is
Last edit: Jury 2026-06-16
Oh. This is not on real silicon? Real hardware?
No, it's a simulator. I'll try it on a real microcontroller later.
I just had a look at the library.
As the Arduino runs at much slower speeds ( it does ) then you may have to add some delays into the library.
Give me 30 mins to change the library.
You gave me an idea. I configured the atmega8 to run at 16 MHz. And, unexpectedly, the sensor showed the correct temperature. After that, I tried an 8 MHz configuration. At this frequency, the sensor also shows the correct temperature. Then I reduced the frequency to 4 MHz and got a result of 0.0625. The atmega8 default configuration runs at 1 MHz.
So, the conclusion is that the code doesn't work at low frequencies.
Try the code below. I want to know if this resolves at these other frequencies.
If I add this code, the display is empty
And yes, if you explicitly specify the frequency as 1MHz in the original code, it also works. I didn't know that if you don't explicitly specify the frequency, it takes the highest possible value.
Last edit: Jury 2026-06-16
Add what code?
Here on the real hardware. Only it's not an Arduino, it's just an atmega8.
So.,the value equates to -1.
I do not have a device here, but, I see that that the library has been optimised for speed.
Add the following to your program. This will be called replacing the existing the library sub routine.
This is restores the time delays.
Test please.