Over Serial Configuration - Sketch 2.5
Overview
RPICT board using Atmega microcontrollers can be configured over serial using a utility written in python. This involves boards RPICT7V1 RPICT4V3 version 2 and RPICT8.
Current version allows changes of
- Output format (csv or Emoncms)
- Nodeid (for Emoncms format)
- Polling (polling interval of data)
- Ical (current calibration value)
- Vcal (Voltage calibration value)
- Vest (estimated voltage for power estimate)
Limitations
Sketch 2.5 allows up to 28 calculation nodes to be computed and 64 output channels. A calculation node being a CT/Voltage couple that provides Irms, Vrms, RealPower etc. A sketch will be released soon to allow up to 40 calculation nodes.
Preliminaries
python serial should be install for the utility to run.
$ sudo apt-get install python-serial
RPICT Configuration tool
The configuration tool can be downloaded directly from the raspberrypi:
$ wget lechacal.com/RPICT/tools/lcl-rpict-config.py.zip $ unzip lcl-rpict-config.py.zip
Reading current configuration
Using the configurator without option only read the configuration stored in the board.
$ ./lcl-rpict-config.py
This yields
# RPICT Configuration Utility # Read only # Now reset RPICT hardware
Once the board has received the reset the configuration will be shown. How to reset the board
# # Structure: 0xb2 # Format: 0 # NodeId: 11 # Polling: 5000 # KCAL: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 545.0 83.3300018311 83.3300018311 83.3300018311 83.3300018311 83.3300018311 83.3300018311 83.3300018311 # VEST: 0.000000 # Nnode: 7 # Nchan: 15 #
Note. Every time the configuration is read from the board it stores a config file in /tmp/rpict.config.
Modify the configuration
To change the values the configurator must be fed with a file containing the new values. We will use the example of a RPICT7V1. Such file looks as below.
[main] format = 0 nodeid = 11 polling = 5000 kcal = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 545. 83.33 83.33 83.33 83.33 83.33 83.33 83.33 vest = 0 Nnode = 7 Nchan = 15 HWSCT = 8 7 6 5 4 3 2 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 HWMCPSCT = 10 10 10 10 10 10 10 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 HWVOL = 1 1 1 1 1 1 1 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 HWMCPVOL = 10 10 10 10 10 10 10 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 CHTYPE = 1 1 1 1 1 1 1 4 4 4 4 4 4 4 3 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 CHID = 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
Online configurator. To help you generating the file above there is an online form available.
We save this in a file called for example rpict7v1.conf. Then we can now start the configurator with the -w option.
$ ./lcl-rpict-config.py -w rpict7v1.conf
Once reset the configurator will read the old config then write the new config and display the newly stored one again.
# RPICT Configuration Utility # Configuration will be overwritten (Ctrl C to cancel) # Now reset RPICT hardware # # Configuration in memory: # # Structure: 0xb1 # Format: 0 # NodeId: 11 # Polling: 5000 # KCAL: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 545.0 83.3300018311 83.3300018311 83.3300018311 83.3300018311 83.3300018311 83.3300018311 83.3300018311 # VEST: 0.000000 # Nnode: 7 # Nchan: 15 # # Writing configuration with file rpict7v1.conf # # Configuration in memory: # # Structure: 0xb1 # Format: 0 # NodeId: 11 # Polling: 5000 # KCAL: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 545.0 83.3300018311 83.3300018311 83.3300018311 83.3300018311 83.3300018311 83.3300018311 83.3300018311 # VEST: 0.000000 # Nnode: 7 # Nchan: 15 #
The configuration file
The configuration file fed in the utility must have the format below:
[main] format = 0 nodeid = 11 polling = 5000 kcal = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 545. 83.33 83.33 83.33 83.33 83.33 83.33 83.33 vest = 0 Nnode = 7 Nchan = 15 HWSCT = 8 7 6 5 4 3 2 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 HWMCPSCT = 10 10 10 10 10 10 10 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 HWVOL = 1 1 1 1 1 1 1 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 HWMCPVOL = 10 10 10 10 10 10 10 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 CHTYPE = 1 1 1 1 1 1 1 4 4 4 4 4 4 4 3 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 CHID = 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
format indicate which format output will be used. Must be an integer number.
0 - CSV
1 - Emoncms
2 - Emoncms as float (must have datatype f setup in emonhub config)
nodeid Only used in emoncms format. Will set the node id.
polling Number of milliseconds between each data to be sent to the raspberrypi.
kcal Current or Voltage calibration coefficient. Formerly Ical or Vcal. Must be contain 5 times 8 values. The first 8 values are for slave1. The second 8 values are for slave2 etc. The last 8 values are for the master board. Each values inside a block of 8 must be in the same order as in Table 1 below. The example above shows for a rpict7v1 vcal=545 then all ical=83.33.
vest Voltage to compute estimated power. Usually 240V or 110V. Must be present even is not used. Set vest=1 to obtain output as ampere instead of watts. Set vest=1000 to get milliampere. Only applies for channel type number 5 (estimated power). Must be set to 0 is computing realpower. Any non zero value will cancel the realpower computation for a calculation node.
Nnode Number of combination node to compute.
Nchan Number of channels (or fields) to output.
HWSCT Pin configuration of a current input. Only first Nnode are relevant.
HWMCPSCT Master or slave identifier for current input. Only first Nnode are relevant.
HWVOL Pin configuration of a voltage input. Only first Nnode are relevant.
HWMCPVOL Master or slave identifier for voltage input. Only first Nnode are relevant.
CHTYPE Type of channel to output. See table below.
CHID Identified from which combination node defined with HWSCT the channel should be output. 0 being the first node.
The 255 in the configuration file are just place holders.
Combination nodes
Combination nodes are small programs in the microcontroller that computes power given a current/voltage couple.
Four given parameters must be provided. They are the pin numbers where to find the current and voltage and also which slave (or master) is to be used.
For example if
HWSCT = 8 HWMCPSCT = 6 HWVOL = 1 HWMCPVOL = 10
will use current ct1 (8) on slave 1 (6) computed against voltage1 (1) on master board (10).
The tables below gives all pin assignment:
Pin number HWSCT/HWVOL |
RPICT7V1 | RPICT8 | RPICT4V3 |
---|---|---|---|
1 | V1 | CT8 | V3 |
2 | CT7 | CT7 | V2 |
3 | CT6 | CT6 | V1 |
4 | CT5 | CT5 | nc |
5 | CT4 | CT4 | CT4 |
6 | CT3 | CT3 | CT3 |
7 | CT2 | CT2 | CT2 |
8 | CT1 | CT1 | CT1 |
Pin number HWMCPSCT/HWMCPVOL |
Board type |
---|---|
10 | Master |
6 | Slave 1 |
7 | Slave 2 |
8 | Slave 3 |
9 | Slave 4 |
Channels
We are refering as a channel here a data stream to be sent out. For example Vrms and Realpower derived from a same sensor will be two different channels.
These are configured with two numbers. The first one is the combination id defined above. Note the first combination id is zero (0). The second number identifies the type of channel. For example:
CHTYPE = 3 CHID = 0
Uses voltage/current combination node id 0. Channel type 3 which is Vrms (as the table below describes).
The table below shows the convention being used:
code | Channel Type | Description |
---|---|---|
0 | None | |
1 | Real Power | Real Power in Watts |
2 | Apparent Power | Apparent Power in Watts. This is Irms*Vrms |
3 | Vrms | Rms Voltage in Volts |
4 | Irms | Rms current in milliAmps |
5 | Estimated Power | Estimated Power in Watts. This is Irms*Vest. |
Restore Default Config
If things go wrong it is possible to reinstate default configuration as shown below.
RPICT7V1
$ wget lechacal.com/RPICT/config/B2/rpict7v1.conf $ ./lcl-rpict-config.py -w rpict7v1.conf
RPICT8
$ wget lechacal.com/RPICT/config/B2/rpict8.conf $ ./lcl-rpict-config.py -w rpict8.conf
RPICT4V3
$ wget lechacal.com/RPICT/config/B2/rpict4v3.conf $ ./lcl-rpict-config.py -w rpict4v3.conf
How to reset the board
Use a small jumper to link the reset pin with the ground. This can be found on the 3x2 6 pin ISP connector.
Make contact with the two pins then remove the jumper. This will reset the board.