Amicus IDE - DS18B20 Sensor

ds18b20_setup

Reading about the Amicus18 left me intrigued to trial it's seamless interfacing. A developer does not need a programmer or USB-UART converters -- it's all onboard. Once your finished writing your program, you hit compile+program and the Amicus IDE will promptly have the PIC flashed.

Also, there's no need to connect different headers or flick switches to "talk" with the device - it all works hassle free with the USB cable connected.

A benifit of the of the on-board USB-UART converter is that the device presents itself as a legacy RS232 COM Port. The Amicus IDE has an excellent Serial Terminal program which will connect to the Amicus18 via the selected port.

So, with all that in mind I wanted my first program touch base with the above features. I had a DS18B20 on the desk, and thought "that will do".

 

DS18B20

ds18b20

The Dallas DS18B20 is a temprature sensor which uses the Dallas 1-wire protocol. A quick review of its features:

  • Each Device has a Unique 64-Bit Serial Code
  • Requires No External Components
  • Range is 3.0V to 5.5V
  • Measures Temperatures from -55°C to +125°C (-67°F to +257°F)
  • ±0.5°C Accuracy from -10°C to +85°C
  • Thermometer Resolution is User Selectable from 9 to 12 Bits
  • Converts Temperature to 12-Bit Digital Word in 750ms (Max)

So it does a fair bit. I like them because they require one-wire for communication, and several devices can be on the same bus.

 

Interfacing with the DS18B20

ds18b20_schematic

The DS18B20s require power, ground and a pullup resistor for the 1-wire bus. That's it.

A 4.7K resistor is the recommended value, you can fudge it by a few Kohm either side if need be.

I've used a Companion Shield for rapid prototyping, and connected the wires as shown on the right. Although the Amicus18 has a 3.3V PIC, there's a 5V output which is clearly marked on the Companion Shield.

ds18b20_setup

As shown in the above picture, the Companion Shield is fitted to the Amicus18 board. The DS18B20 is in the shiny steel cylinder on the right. There's not much to it, and this is a good example of how the Companion Shield can easily be used to prototype with different widgets.

 

The Source Code

Amicus IDE DS18B20 Code Example
' Amicus18 Project A0001: DS18B20
 ' 
 ' Author: Graham Mitchell
 ' Date: 20 Jun 2010
 '
 ' Comments: 
 ' This is a simple project which interfaces with a DS18B20 temperature sensor. 
 ' The received scratchpad contents is displayed via the Amicus Serial Com tool.
 ' Temperature is displayed in degrees C and F.
'
' For more information and updates, please visit digital-diy.com
 
Dim SPTemperature As Word ' scratchpad temperature storage
Dim Reserved0 As Byte ' scratchpad reserved variable
Dim Reserved1 As Byte ' scratchpad reserved variable
Dim Reserved2 As Byte ' scratchpad reserved variable
Dim Reg_TH As Byte ' scratchpad TH register or User Byte 1
Dim Reg_TL As Byte ' scratchpad TL register or User Byte 2
Dim Reg_Config As Byte ' scratchpad configuration register
Dim CRC As Byte ' scratchpad CRC register
 
Dim Temperature As Float ' temperature result
 
Symbol DQ = PORTB.0 ' one-wire data pin
 
HRSOut 13,"Amicus18 DS18B20 Project",13
HRSOut "Visit digital-diy.com for more information!",13,13
 
While 1=1
 OWrite DQ, 1, [$CC, $44] ' start temperature conversion
 
 While ORead DQ, 4 = 0 ' check for still busy converting
 Wend 
 
 OWrite DQ, 1, [$CC, $BE] ' read the temperature
 ORead DQ, 0, [SPTemperature.LowByte, SPTemperature.HighByte, Reg_TH,Reg_TL,Reg_Config,Reserved0,Reserved1,Reserved2,CRC]
 
 ' display scratchpad contents
 HRSOut "********************************************",13 
 HRSOut "DS18B20 Scratchpad: " 
 HRSOut Hex SPTemperature.LowByte, " ", Hex SPTemperature.HighByte, " ", Hex Reg_TH, " ", Hex Reg_TL, " " 
 HRSOut Hex Reg_Config, " ", Hex Reserved0, " ", Hex Reserved1, " ", Hex Reserved2, Hex CRC, 13
 
 Temperature = 0.0625 * SPTemperature ' convert to degrees C
 HRSOut 13, Dec Temperature, " C"
 
 Temperature = 1.8 * Temperature + 32 ' calculate temperature in degrees F
 HRSOut ", ", Dec Temperature, " F",13
 
 DelayMS 1000 ' Display once a second
Wend

 

Programming the Amicus18

I did a quick screen capture while programming the Amicus18 board, and then opening the Serial Terminal to talk with the PIC microcontroller. It's allot easier than typing, so here it is:

As you can see, the whole process is very easy. The guys at Crownhill have done an awesome job thus far, here's hoping they keep the momentum behind Amicus products.


Posted: 6 years 11 months ago by W4GNS #12550
W4GNS's Avatar
As a quicky I used the code in this article today, but used a LCD versus a terminal. To drop the last 3 digits I used fRound in the print command.
Print At 1,1,Dec fRound Temperature, " F"
Posted: 6 years 11 months ago by Roger #12558
Roger's Avatar
Hi Graham,

The link "Read full article" seems to be broken

Roger
Posted: 6 years 11 months ago by Jon Chandler #12559
Jon Chandler's Avatar
Until Graham gets a chance to fix the link, the article is here.
Posted: 6 years 11 months ago by W4GNS #10
W4GNS's Avatar
Actually I did not post enough code for someone else that may run upon this and need to do a quicky. Whats needed to print to LCD on an EasyPic7using a 18F45K22 is:
Declare LCD_DTPin PORTB.0
 Declare LCD_ENPin PORTB.5
 Declare LCD_RSPin PORTB.4 
Declare LCD_Lines 2
 Declare LCD_Type ALPHA
 DelayMS 2000 
Cls
 Print At 1,1,Dec fRound Temperature, " F"
 Print At 2, 1,"www.digital-diy.com"

I gave a demo to a neighbor on how quickly you could throw together some code, or simply copy-n-paste in this example. She was impressed at how uncomplicated microcontollers could be. Using my EasyPic7 board I Googled and had a temp displayed on a LCD in a few short minutes, needless to say she was impressed. I may have added another soul to the Microchip ranks.

Forum Activity

  • No posts to display.

Member Access