CT Calibration selection from Pi2

I was able to configure my CT types on my emonPi2 from the emonPi2 install guide. Now I’d like to do the same on my emonTx5 device, but I didn’t see anything in the emonTx5 install guide to describe the process. I’m not sure if configuring the Tx5 from the Pi2 is something that I should expect to be able to do in general.

I thought maybe I could connect to ttyS0 instead of ttyAMA0, but that didn’t seem to work.

The emonPi2 and emonTx5 are connected to each other via USB-C.

I’d be fine with connecting it to a computer via USB-C and using a python script to set these values. I already used emonupload2.py to flash a different firmware on there, so I’m familiar with the emonscripts repo.

I noticed the web console said it was running ‘/var/www/emoncms/scripts/serialmonitor/start.sh 115200 /dev/ttyAMA0’. So I checked out the emoncms repo. In serialmonitor.py it correctly detects if the python redis library is available, but then it uses this r variable unconditionally causing an exception. With the redis library installed it fails to connect to a redis server. :roll_eyes:

Hopefully there is some standalone script that can let me set these values, because trying to pull the ones out of emoncms and use them in a standalone manner isn’t going great.

Hi @doctor_docs - just to check this statement, are you connecting the two together through the USB-C ports? On both of them, the USB-C port is a device, rather than a host. If you connect the Tx5 to a host (your computer, or the emonPi2’s USB-A port if you are not using a RPi Zero), it should appear as a serial TTY device.

Hope that helps - I noticed someone else had that issue yesterday, so could do with mentioning in the documentation.

I had them connected from USB-C to USB-C.

It hadn’t occurred to me that it might just be opening a terminal over USB, but after you suggested that, I realized that it should have been obvious from the name “serialmonitor” that it was just a UART device (or similar).

I connected a laptop to the EmonTx5 again and used screen to open a terminal to /dev/ttyUSB0 (I use Linux) at a baud rate of 115200. screen showed the output that I was seeing in the web console, so that’s good, but it doesn’t accept any input from me.

Trying to list the devices with a lowercase L and “enter” doesn’t echo anything to the screen (which may be expected) nor does it show me the list of devices again. I checked the Python code to see if there were any abnormal flags like flow control, parity bits, and so on. It just provides the device and baud rate, which is the same as I’m doing with screen. I’ve used screen to send data to devices before, so I know it’s not a limitation of screen.

So I tried switching gears. I connected the emonTx5’s USB-C into a USB-A port on the emonPi2 and went to the serial config tool in emonCMS. I stopped EmonHub and tried connecting to ttyUSB0 and all I get is a javascript error:

EmonCMS Error
-------------
Message: TypeError: app.emontx.channels[(c - 1)] is undefined
Route: admin/serconfig
Line: 584
Column: 44

I searched the emonCMS issue tracker to see if there are any open (or closed) tickets about app.emontx.channels but it didn’t turn anything up.

The web based serial configuration tool still works fine when I refresh the page and try to connect to ttyAMA0.

Any hints on what I should do differently? How so other people configure their emonTx5 devices?

Edit to add: I found that the Serial Monitor page of emonCMS (as opposed to the Serial Config page) does not give me a javascript error. It connects to ttyUSB0 just fine and I can run commands. I expected h or help to work, but it turned out to be ?.

I don’t understand what values I need to enter to switch the CT type, so if there’s some place in the manual I should be looking for additional information, please point me there. I’ll probably also link to it when I submit a change to the documentation about CT Calibration.

Checking the common “AVR” software from Github a little while ago for someone else, I found the ‘l’ (List) command didn’t work for me either (Ubuntu Linux). I tracked it down to what I think is faulty programming in the configuration part of the sketch, where in parsing the command a check is made on the length of the command string (“len = …”). From memory, the test is “==1” and I found the actual length was 2. Trystan thinks it’s not a problem. The line ending sent (CR, LF or both) might be relevant. I was using the Arduino IDE V1.8.

If you’re in sleuth mode, that’s where to start looking.

avrdb_firmware/emon_DB_12CT/emon_DB_12CT_config.ino at master · openenergymonitor/avrdb_firmware · GitHub Line 312. And all the commands are at the top of that file.

I wrote the original “config” sketch back in 2021 and it’s documented here The emonPiCM, but I didn’t recognise some significant parts so it’s been changed since. I’m quite sure the original code worked as documented.

1 Like

I wrote some notes on connecting a Linux computer serial terminal to an emonTx4 via USB,
which may (or may not - I don’t have an emonTx5!) be helpful:

So, the issue is that screen doesn’t send a newline \n when you press Enter, so the emonTx is not recognising it. I don’t use screen, but I don’t think there’s a way to force it to do so. You could use another terminal, such as minicom. The convention/standard is that the device sends \r and the host does the \n but it’s a bit of a wild west in terms of implementations.

@TrystanLea will confirm, but you should be able to use the same process to configure the Tx and the Pi as they are essentially the same. In the emonPi, there is a RPi attached directly to the microcontroller’s serial port and in the Tx, you connect to that same serial port through the USB port.