Modbus Sensors (BP Sensors) with TPS/WS1102
Hardware Requirements:
TPP2-G2 board/WS1102 Device
Power Tibbit #09 or #10 or #33,#18, Connector Tibbit #20 and RS485 Tibbit #05, for TPS setup
BP Sensor or any Modbus Sensor
Power source to power TPS and for Modbus Sensors
Router for LAN/WIFI Network
Jumper cables
Software Requirements:
TPP2-G2 TiOS firmware (4.00.01)
WS1102 TiOS firmware (4.01.02)
TDST (Tibbo Device Server Toolkit)
TIDE (Tibbo Integrated Development Environment)
Device Explorer application preinstalled on your PC
WS1102 Connection Layout:
Connecting the Modbus sensor to WS1102 is simple enough but not that simple compared to the TPS device. With WS1102, you need to be careful as WS1102 can't supply the power to the sensors, so we need an external power supply to the Modbus sensors or RS485 bus. Tibbo's BP sensors can accept the supply voltage in the 4V to 15V range, while for third-party sensors the power supply requirements you need to check in the datasheet of the respective manufacturer.
While configuring it with CODY, the pin assignment will be displayed and you can make the connections accordingly, in my case, the connection layout with WS1102 is shown in the below snapshot.
TPP2-G2 (TPS) Connection Layout:
TPP2-G2 board (TPS) with RS485 Tibbit #05 the connection consist of 4 jumper cables connected to the Modbus sensors. The Modbus sensor (BP Sensors) is getting the power from #05 from IO3 (VCC) and the ground from IO4 or either you can connect the ground to the TPS system on pin 5 of the 9-pin connector Tibbit #20.
NOTE: Please don't forget to use 120 Ohm termination resistors on both ends of the RS485 bus.
CODY for Startup:
Generate the project using Cody by selecting the TPP2G2/TPP3G2 boards as your device and adding the respective Tibbits even you can select WS1102 and make the connection layout shown in the snapshots above.
The code generated by CODY is perfect for TPS and WS1102, but you need to check the difference when you are using TPS and WS1102, which means the debug mode of WS1102 should be kept "net" and "auto-connect" parameter should be kept as "yes". The rest of the parameters can be the default, but to avoid any confusion I have listed all the parameters below before uploading the application on WS1102.
For more details and default values of all the parameters, you can check Tibbo's online documentation of WS1102 here.
autoconnect = yes
domain = US
ssid = as per your WIFI LAN
password = as per your WIFI LAN
dhcp = yes (for testing purpose)
debugmode = net (WIFI)
defaultapp = 1
And for TPS it is pretty simple and straightforward, we will debug with the Ethernet port on LAN.
Modbus Configuration:
Please remember that the communication of Modbus sensors in the current setup is on the "Serial" Port, which means we are using the "Modbus RTU protocol" with both WS1102 and TPS.
While generating the project on CODY, please select the RS485 serial parameters as 38400-8-N-1, because Tibbo's BP Sensors are able to communicate at 38400-8-N-1, while any third-party Modbus sensors can have different parameters, so in CODY we have given the complete freedom to select the respective serial parameters for your sensors.
Please follow the snapshots below for details:
The Modbus configuration in CODY remains the same for both TPS and WS1102 devices. In my setup I have selected 2 units of Light sensors and 1 unit of 3-axis accelerometer sensor, just to make you show the difference in the CODY configuration if you have multiple numbers of the same (Light) sensors and a single sensor with more than 1 readable registers (3-axis accelerometer). TPS/WS1102 is selected as Modbus Master and we need to add the slave devices which are Modbus sensors with all the respective details.
In the above snapshot, you will observe that the 2 light sensors are added but have different device IDs this clears the thought on how to add multiple devices of the same characteristics, and adding the respective register details in CODY will clear your doubts on adding multiple registers of a single slave device.
For the 3-axis accelerometer sensor, we will select 1 unit of slave device with the device ID and add multiple registers to read X, Y and Z-axis.
For more details on Tibbo's various BP sensors and their respective register address, you will find it here.
After finishing the Modbus configuration, you can select the LAN/WIFI configuration TPS/WS1102 respectively in the "Features" tab, enable the Ethernet/WIFI feature and fill in the respective IP address, Subnet mask and Gateway address of your LAN/WIFI network.
App Blocks - CODY:
Now after we finish the Modbus and basic LAN/WIFI settings for the devices, we need to add the logic to poll the data from those registers periodically. For this and many other similar logical concepts, we have introduced "App Blocks" in CODY, using App blocks the user can just drop the blocks on the grid and connect them logically to add the respective code structure in the backend to fulfil their logic.
To simplify this, we have added multiple blocks like:
- Utilities (Systemhalt, current time, add constant/variable/delay in your logic)
- Network (Basic LAN setting can be added using with/without DHCP feature)
- Output (To display variable values in debug window using sys.debugprint syscall in the backend)
- Input (Button press feature is used using on_button_press syscall)
- Math (various programmable operators are added like: add, subtract, multiply, divide, /greater/less than)
- Logic (compare 2 variables/parameters on non equality/equality basis)
- Other (App blocks will generate a block (in my case it is Modbus) on your custom configuration for simplicity)
More blocks will be added in the future and on the user's suggestion to simplify the process and user's logic. Now to poll the data from the respective registers, the Modbus block is available in the "Other" subset, we can add the "Timer" block and attach it to all the available sensor blocks in the project and do little processing to print the values in the debug window.
While playing with the App blocks you need to be careful in handling the data types, in my case the 3-axis accelerometer sensor data in the Modbus block is handled as "word" so I need to process the data to convert it to "Float". We are dividing it with a constant "10.0" and NOT with "10".
While for the Light sensor, we don't have to process the data, we can directly debug print it.
sub X_axis_data_available(registerValue as word)
dim arithmatic_result as float = registerValue/CONST_10_X
sys.debugprint("X-Axis"+(ftostr(arithmatic_result,FTOSTR_MODE_AUTO,5)+ "\r\n"))
end sub
Please check the respective App block details of defining the constant and converting it into Float.
The complete App block structure to print every sensor data used in the project is shown below.
Download the project file to your computer, and if you want to make any changes to the TIDE project file, you can change the IP address or change the respective pin assignments on TPS/WS1102.
You can check and verify the respective code structure added by the App blocks in "device.tbs" on the function called "callback_modbus_slave_reply".
case Light_1_DEVICE_ID:
if request_item.start_register=500 then
dim Light_1_Light_1reg_val as word = modbus_read_word(bytes,0)
Light_1reg_data_available(Light_1_Light_1reg_val)
end if
case Light_2_DEVICE_ID:
if request_item.start_register=500 then
dim Light_2_Light_2reg_val as word = modbus_read_word(bytes,0)
Light_2reg_data_available(Light_2_Light_2reg_val)
end if
case Acclero_DEVICE_ID:
if request_item.start_register=600 then
dim Acclero_X_axis_val as word = modbus_read_word(bytes,0)
X_axis_data_available(Acclero_X_axis_val)
end if
if request_item.start_register=602 then
dim Acclero_Y_axis_val as word = modbus_read_word(bytes,0)
Y_axis_data_available(Acclero_Y_axis_val)
end if
if request_item.start_register=604 then
dim Acclero_Z_axis_val as word = modbus_read_word(bytes,0)
Z_axis_data_available(Acclero_Z_axis_val)
end if
And the debug print code structure is added just below the same function as:
sub X_axis_data_available(registerValue as word)
dim arithmatic_result as float = registerValue/CONST_10_X
sys.debugprint("X-Axis"+(ftostr(arithmatic_result,FTOSTR_MODE_AUTO,5)+ "\r\n"))
end sub
sub Y_axis_data_available(registerValue as word)
dim arithmatic_result as float = registerValue/CONST_10_Y
sys.debugprint("Y-Axis"+(ftostr(arithmatic_result,FTOSTR_MODE_AUTO,5)+ "\r\n"))
end sub
sub Z_axis_data_available(registerValue as word)
dim arithmatic_result as float = registerValue/CONST_10_Z
sys.debugprint("Z-Axis"+(ftostr(arithmatic_result,FTOSTR_MODE_AUTO,5)+ "\r\n"))
end sub
sub Light_1reg_data_available(registerValue as word)
sys.debugprint("Light_1:"+str(registerValue)+""+ "\r\n")
end sub
sub Light_2reg_data_available(registerValue as word)
sys.debugprint("Light_2:"+str(registerValue)+""+ "\r\n")
end sub
Connect the TPS/WS1102 device to the power supply and LAN/WIFI network and compile the application to check for any errors.
After compiling, select the target device (TPS/WS1102) and start to debug, try to move the 3-axis accelerometer sensor to reflect the changes in the readings and cover the top lid of the light sensor to reflect the changes in the readings.
The final results will appear like this.
Comments
0 comments
Please sign in to leave a comment.