Directly connecting Emontx and Raspberry PI?

Hi,

Im new here so forgive my upcoming stupid question/s.

Im planning my energy monitoring solution using emontx, raspberry pi and an old laptop gathering dust. Not sure weather dusty the laptop or PI will run local emoncms, but I also want to send data onto Sen.se for viewing.

I have about 10 circuits to monitor and thought about stacking emontx units as someone posted here

What I want to do is directly connect the emonTx stack to the Raspberry PI as they will be situated in the same enclosure.

How do I do this? Would I use I2C as well with SDA and SCK signals? What about ISP? or even FTDI?

 

Then I also want to add some control in addition to the monitoring above and integrate that with openRemote [or is there a control project here and methods and mobile app from emon?]. There are GPIO on emontx and pi that I want to use for this and somehow integrate that into the same hardware [dusty or pi] running emoncms.

Thanks in advance from South Africa

MartinR's picture

Re: Directly connecting Emontx and Raspberry PI?

What I want to do is directly connect the emonTx stack to the Raspberry PI as they will be situated in the same enclosure.

Should be fairly straightforward. You'd need to connect the master emonTx to the Pi via the serial ports and then replace the emonTx RFM12B code with the serial code from the sketch for the Pi daughter board.

nubble's picture

Re: Directly connecting Emontx and Raspberry PI?

Is it safe to assume that the serial ports connection between emontx and pi is not the same as the i2c bus between the stackable emontx units?

What are the pins on the emontx called for the serial ports? ISP? The same for PI?

btw. Martin great work with your 3-phase solar PV monitoring.

MartinR's picture

Re: Directly connecting Emontx and Raspberry PI?

Yes, the serial ports and I2C ports are completely independent. I suggested using the serial port because that's how the Pi daughter board currently talks to the Pi. You could use the SPI instead but then you'd have to modify the Pi scripts.

The emonTx serial port is also used for programming so you will have to bare that in mind and you'll also have to remove any serial print statements.

The emonTx serial port is connected to both the FTDI header and the PWR.SER/I2C header. You'll find all the info you need on pinouts etc. on the schematics for the emonTx and Pi daughter board.

chacal's picture

Re: Directly connecting Emontx and Raspberry PI?

I am interested in this project too. Did you make something working in the end Nubble? Do you think you could give us pinout connections you made. Any code modifications at all?

chacal's picture

Re: Directly connecting Emontx and Raspberry PI?

I certainly need you guys help.

Am I correct assuming the rfm12pi only convert a radio signal to a serial message on the rpi? Then all I need to do is connecting an arduino rx/tx to the rpi rx/tx. Then hopefully that should not need any code change in the raspberrypi_run.php script and nothing in the arduino sketch too.

I looked at this page here and I might have to do a level conversion between the 3.3V and 5v. I might opt for the resistor bridge.

Let me know if that's the right track. Thanks.

 

chacal's picture

Re: Directly connecting Emontx and Raspberry PI?

I wish I had more support. :(

Direct connection with serial does not seem possible without any code change of the raspberrypi_run.php script. I checked the serial output of the emontx and it differ from what the Raspberrypi receives normally with the rfm12pi. Ideally I'd prefer changing too much code if possible.

chacal's picture

Re: Directly connecting Emontx and Raspberry PI?

Jérôme's picture

Re: Directly connecting Emontx and Raspberry PI?

> Am I correct assuming the rfm12pi only convert a radio signal to a serial message on the rpi?

Correct.

> Then all I need to do is connecting an arduino rx/tx to the rpi rx/tx.

Yes.

> Then hopefully that should not need any code change in the raspberrypi_run.php script and nothing in the arduino sketch to

You'll need to change (simplify) the code in the arduino to remove the "RF" layer, basically, to let the output format stick to what the RPi expects to receive.

Besides, there is a layer of data encoding you don't need when using a simple serial link. You may want to remove such encoding in the arduino code and simplify the code in the RPi. (I'm referring to the fact that numbers are sent as unsigned chars and thus are scaled, and all).

The pylink would help but may need adaptation (node ID is hardcoded). It is meant as an exemple to build upon. I'm working on a rewrite of the python gateway that runs on the RPi and it should be able to read serial input (not yet, work in progress) of the form :

NodeID val_1 val_2 val_3
NodeID val_1 val_2 val_3
NodeID val_1 val_2 val_3

 

chacal's picture

Re: Directly connecting Emontx and Raspberry PI?

Thanks Jérome , I am just waiting on my logic level converter to arrive and some more cables. Then I can test all that.

 

chacal's picture

Re: Directly connecting Emontx and Raspberry PI?

Right I have this connected and I can read my emontx output on the rpi serial port.

The pylink looks like the easiest option for me. I understand what the emontx outputs, that's quite clear. BUt I can't make any sense of what the rpi expect (I can see my node ID on the first two character but that's all.)

What Rpi expect:

10 9 2 0 0 0 0 109 11                                                  
 10 6 2 0 0 0 0 109 11                                                  
 10 7 2 0 0 0 0 109 11                                                  
 10 7 2 0 0 0 0 109 11                                                  
 10 13 2 0 0 0 0 109 11      

What emontx outputs:

17 19 17 3236
13 15 15 3236
15 16 16 3227
14 17 18 3227
16 20 16 3236
13 20 15 3227
 

Also I know python well but not much php. So I'll avoid tempering with the rfm12piphp for now...

 

 

chaveiro's picture

Re: Directly connecting Emontx and Raspberry PI?

Why not arduino the ethernet directly?

I've this solution for a few weeks and it's fine.

Jérôme's picture

Re: Directly connecting Emontx and Raspberry PI?

If you mean adding ethernet to the emonTX, sure, some people do.

The design choice of OEM is to have a single base with ethernet connection to a modem, along with one or more emonTX communicating with the base by RF. The reason for this being that the router is not necessarily close to what we measure. .

chacal's picture

Re: Directly connecting Emontx and Raspberry PI?

Right. I have completed this now. Thanks for your help.

On the hardware side I connected the serial link from the ftdi port of the emontx to the gpio serial link on the rpi. In between the two I have used a "logic level converter" bought for three quids on the web. (note rfm12pi and rfm12b are absent on this setup)

On the coding part I managed not to have to modify anything in the Rpi. (I made the pylink working but gave up that option) The emontx sends data in the same way the rfm12pi does. For this I took a basic CT_123 sketch and removed anything that concerns rf (mainly because I did not connect a rfm12b). Then for each sensor value that is sent I have formatted them with the 2x 8bit that the php script expect. I used the function below:

void print_formatted(signed short nData)
{
  unsigned char nDataMSB = nData >> 8 ;
  unsigned char nDataLSB = nData ;
  Serial.print(" "); Serial.print(nDataLSB);
  Serial.print(" "); Serial.print(nDataMSB);
 
}

Then somewhere in the loop function I can use:

print_formatted(emontx.power1);

All this works pretty nicely. Obviously the limitation is that only one emontx can be used but in my case of application this is not an issue.

I guess this is all fairly simple for the audience of this forum here. I just wanted to post a small recipe if someone intend to take the same path.

PeterN's picture

Re: Directly connecting Emontx and Raspberry PI?

Hi, Great work this is something I wanted to try for a while ( unfortunately not an expert ) and when I read your post I ordered a logic level convertor. Connectivity setup seems easy enough and I am receiving ok (minicom).  Tried above emontx code above but couldn't get it to work fully e.g. receiving ok but wrong format. Could you please share your emontx sketch. I have assumed your using standard Raspberry Pi Module (php code).

Thanks

Peter

chacal's picture

Re: Directly connecting Emontx and Raspberry PI?

Hi Peter,

Good to hear you are into this as well. Yes I use the standard php service running on the Rpi. Nothing to change on the Rpi (except that you disconnect the rfm12pi of course).

I have the project to make a circuit board that will make a clean and easy connection between the ftdi and the gpio's.

My setup for this particular project is a single box emontx/rpi together with wifi on the rpi. I plan to use several of them for some estate properties on which I need just electrical monitoring. Hence no need for multiple emontx's.

I am attaching a sketch that I have been modifying. Note I have inserted more code for doing CT and temperature together. Just ignore what I added for temperature.

I hope that will help.

chacal's picture

Re: Directly connecting Emontx and Raspberry PI?

right... took me a little while to find out how attachements works here. Getting there...

PeterN's picture

Re: Directly connecting Emontx and Raspberry PI?

Hi Chacal,

Great thanks, let you know shortly.

I'm using 3G dongle and similarly would like to have emontx in same enclosure. I've got wifi ( TPLink -Argos) working with XBMC on Raspberry Pi but having some problems with emoncms ready to go image.

Thanks

Peter

 

 

PeterN's picture

Re: Directly connecting Emontx and Raspberry PI?

Hi Chacal,

Thanks again, it's working - no changes. I'll leave it over night.

Cheers Peter

chacal's picture

Re: Directly connecting Emontx and Raspberry PI?

I have finally completed a little board that connects rpi and emontx together directly.

pm me if you are interested in one of them.

 

jb79's picture

Re: Directly connecting Emontx and Raspberry PI?

Hello!

Do you have a schematic for this project that you can share?

best regards Juergen Brenner

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.