|Description||This application note does not describe fully how to create the application example which is provided in the ZIP file of this application note. This application note aims to explain how to use the example so it can be modified or integrated into applications by the user.|
|Supported Processor||PICASO, DIABLO16|
This application note demonstrates how to connect to one or more 1-wire sensors using a Picaso or Diablo16 Display Module. Before getting started, the following are required:
- Any of the following 4D Picaso display modules:
and other superseded modules which support the ViSi Genie environment
- The target module can also be a Diablo16 display
Visit www.4dsystems.com.au/products to see the latest display module products that use the Diablo16 processor.
- 4D Programming Cable / µUSB-PA5/uUSBPA5-II
for non-gen4 displays (uLCD-xxx)
- 4D Programming Cable & gen4-IB / 4D-UPA / gen4-PA
for gen4 displays (gen4-uLCD-xxx)
- micro-SD (µSD) memory card
- Workshop 4 IDE (installed according to the installation document)
When downloading an application note, a list of recommended application notes is shown. It is assumed that the user has read or has a working knowledge of the topics presented in these recommended application notes.
This application note does not describe fully how to create the application example which is provided in the ZIP file of this application note. This application note aims to explain how to use the example so it can be modified or integrated into applications by the user.
This application note will not explain every step of the way, so please refer to the application examples in the ZIP file of this application note download, to see the finished applications.
For instructions on how to launch Workshop 4, how to open a ViSi project, and how to change the target display, kindly refer to the section “Setup Procedure” of the application note
For instructions on how to create a new ViSi project, please refer to the section “Create a New Project” of the application note
This Application Note contains 2 application examples inside the ZIP file. Start with the Application called 1-Wire-Discovery.4dViSi
This application example (1-Wire-Discovery.4dViSi) is designed to scan the 1-wire bus when a single 1-wire device is attached, in order to gain its Serial Number, so the 1-Wire device can be addressed when more than 1 device ends up being connected to the bus. It can also be used if only 1 device is going to be used, as it displays the Temperature also.
The Application example looks like the following:
The second application in the ZIP is called 1-Wire-Multiple.4dViSi
This application example (1-Wire-Multiple.4dViSi) is designed to address 2 hard coded DS18B20 sensors, displaying the serial numbers that have been hard coded in, and the live temperatures presented from these sensors.
This application must be edited with the Serial Numbers discovered from the 1-Wire-Discovery.4dViSi application first in order to work.
The Application example looks like the following:
There are numerous 1-wire devices available on the market. In this Application Note, DS18B20 Temperature Sensors have been used.
The 1-wire protocol from 4D Systems allows the bus to be scanned for a device if a single device is present on the bus, and the serial number extracted so the sensor can be addressed. If more than 1 devices are to be addressed on the bus, they initially need to be identified to the user individually so their serial number can be extracted. It is not possible to scan the bus when multiple devices are present.
In the 1-Wire-Discovery.4dViSi application example, the full application (1-Wire-Multiple.4dViSi) has been cut down to aid with the understanding of what is going on in the application.
Open up this application by double clicking on the 1-Wire-Discovery.4dViSi file from Windows Explorer, or by going File – Open in Workshop 4.
Read the description at the start of the application
The application is set to use pin IO5 on the uLCD-43PT. If you wish to use another pin, simply change the constant on line 38
This section of code performs a 0x33 command which is essentially a broadcast the 1-wire bus and all sensors present on the bus will reply. This therefore only works correctly if 1 device is on the bus as they will all try to reply at the same time and the received message will be all gabled and therefore not usable.
This code will then print out the 16 byte serial number that has been discovered, to the display, in Hexadecimal.
For example, the output may be: 281A2AC9040000FB
This is made up of 16 bytes, 0x28, 0x1A, 0x2A etc
This number should be noted down if you are intending to use more the 1 device on the bus. If you only have 1 sensor, then you do not need to use the 1-Wire-Multiple.4DViSi application example.
The next section of code is the main loop, which will loop every 500ms, and communicate with the DS18B20 sensor and return its temperature value, and then display it on the display using the LED Digit object.
This achieves this by doing a 1-Wire bus reset, which is required prior to sending a new command to the bus. It then sends a 0x55, which tells the bus a Serial Number is going to follow, to address a specific sensor. Since the bus has already been scanned and saved above, the serial number has been saved into the serial_number array. This is then used when addressing the sensor.
The serial number is then sent to the bus using a for loop, writing each of the 8 bytes one at a time. The 0x44 command is then sent telling the DS18B20 to start a temperature conversion.
The bus is then reset again, and a 0x55 is sent once again, followed by the serial number. The 0xBE command is then sent telling the DS18B20 that the temperature is wanted to be read. The scratchpad is then read as 2 bytes, and then converted into a temperature.
The temperature is then sent to the LED Digits object on the display.
This application can be used if there is only 1 DS18B20 sensor on the bus, or to discover the serial number of multiple DS18B20 sensors 1 at a time. The serial number can then be noted down. Repeat process if more than 1 sensor is to be used, noting down the serial numbers. Using the 1-Wire-Multiple.4dViSi application, multiple devices can be then present on the bus at the same time.
The 1-Wire-Multiple.4dViSi application is the full application for this Application Note. It features the code from the 1-Wire-Discovery.4dViSi application, along with addition code used to address 2 DS18B20 sensors. The same principle can be used for more than 2 sensors, however this demo only features 1 form showing 2 sensor values.
Please take note of the description at the top of the application
As per the 1-Wire-Discovery.4dViSi explanation section, if the desired pin used for the 1-wire bus is desired to be anything other than IO5 on the uLCD-43PT, then this can be changed on line 39 of this application.
On line 83 is some code which is found in the 1-Wire-Discovery application, which has been commented out. This has been replaced with code below it, which stores 2 hard coded serial numbers in arrays, used to address 2 sensors on the bus, see lines 101 and 102.
Code starting on line 105 will print the first serial number out to the display. Code starting on line 114 will print the second serial number to the display.
Inside the main loop starting on line 127, is the code which is used to retrieve the temperature of the sensors. This first section of code reads from the first sensor and then displays it on the first LED Digit on the display. Please refer to the 1-wire-Discovery application explanation section for detail.
The code following that starting on line 157 will do the same but for the second sensor, and display it on the second LED digit of the display
The program can be compiled and downloaded to the display.
It should also be noted that the 1-Wire-TEMP.inc file contains the code which defines the 1-wire Protocol, and is included in the Application example at line 37.
For instructions on how to save a ViSi project, how to connect the target display to the PC, how to select the program destination (this option is not available for Goldelox displays), and how to compile and download a program, please refer to the section “Run the Program” of the application note
The uLCD-32PTU and uLCD-35DT display modules are commonly used as examples, but the procedure is the same for other displays.