News:

To visit MidNite Solar click this link www.midnitesolar.com

Main Menu

rs232 modbus to Classic

Started by dgd, February 05, 2015, 03:48:23 AM

Previous topic - Next topic

WillEert

       Well I have built this system and tried to run it using the lower Classic RJ11 port. The code worked great in that the lcd display worked well however I did not get a connection to the Classic and see Classic data. I suspected my pinout on the cable or a bad connection and spent some time looking at that however the cable did not seem to be the problem. I changed the pinout to allow use of the middle port and everything worked very well. The code worked great and the LCD display was very nice. I saw the Classic data and it updated nicely. I changed the pinout back to the lower port and once again I did not see the Classic. Does anyone know what might be different about the lower RJ11 port? Might it not access the registers that the upper 2 ports do? Possibly a different address or something? Possibly one of the different wires that I use due to the different pinout is damaged. I would like to use the lower port my diversion control as I am using the middle port for my MNGP remote which I enjoy looking at wile I am in my kitchen. I guess that I could have the arduino display as a remote and do the diversion control however I would prefer not to have to take that route.

Thanks

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

dgd

Hi Will,
I never tried the third (lower) rj11 port but I did note the only difference is the RX and TX are reversed.
Does the remote MNGP work when plugged into the third  rj11?
I seem to remember reading somewhere  it would work in either port so maybe it auto detects which is TX and RX.
dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand

WillEert

HI djd,

I tried the remote in the lower port. It did not work. I could not figure out how it would work because as you say the TX and RX wires are reversed. I do not know about auto detection but it would need to have something like that. Also it has no +9v power which I would guess the MNGP needs to work. Since this port is the second half of the follow me system the pinout of the lower port makes sense in that it is the reverse of the middle port. I know my pin 3 and 4 wires are good because they worked when I used the middle port. Maybe my pin 2 wire a has a problem preventing a ground connection which would stop the RS232 system from working.

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

WillEert

Continuing the thought of the lower port being primarily a follow me port maybe it will not work unless follow me is enabled?

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

WillEert

Managed to get the Uno via rs232 to Classic system to work on the lower RJ11 port. Yay! I had to reverse the RX and TX pins from what the drawing in the Modbus Network Spec suggested it should be. So for me GND is pin 2, RX is pin 3 and TX is pin 4 on the lower RJ11 port.

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

dgd

Excellent. Just another of those little documentation errors placed there to test your resolve. Its surprising nobody found this before  :o

dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand

dgd

Will,
The use of the lower rj11 serial port has me thinking now that a second Arduino could be connected to a Classic.
So rather than have the one Mega or DUE being a web server AND controlling other devices it may a better design to keep the web server just web serving and therefore fast on 1 second modbus reads - then use an UNO on the lower port to manage water heating - PWMing relays etc. It could probably also talk to the web server to provide info on how the water heating is progressing
LCD display on UNO optional   :)

dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand

WillEert

Hi dgd

I like the idea of using both of the available RJ11 ports on the Classic. Since the arduino does not really do two things at once very well your idea  really makes sense.

Will 
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

WillEert

A tale of woe about a nubies attempts to learn about RS232 communication with the Classic.

        I want to write to the Classics 4148 register Battery output Current Limit so I configured, using the SimpleModbusMaster library example as a template, what I thought should work. I was in doubt about the meaning of the last line of code which actually writes to the register however I put the value that I wanted the register to take in the () replacing the AO in the example. The first time I tried the Classic was not happy. It went to mode off and offered the error - battery overvoltage. I reset it after some head scratching and got it going again. One thing I had done was I did not multiply the PV *10 so although I put in 65 in the packet the Classic of course saw 6.5. It took this value but s/d. I had to reload most of its parameters to get it to go again. I do not have an unlimited supply of Classics to destroy so I was not happy with my performance in this instance. I tried again using 650 as a value. It took this value but once again went to off mode- this time without an error message. I retreated in disarray after resetting my Classic......

        I went over cpfl's code as he is writing to the Classic successfully with his nice diversion system however not knowing Python? and having only a basic understanding of C it did not help me much. I poked around the arduino site and the web but did not get an understanding of where I am going wrong. I am posting the code I used with the rs232 writing code commented out . I am making an error in the code somewhere but so far have not been able to find what it is.

Will

(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

WillEert

I think I am starting to determine what I did incorrectly. I found the SimpleModbusManual which is helping me out. Looks like I may have written the same value to three registers. Also the manual states that the FSM does not like delays in excess of 100 msec and this sketch has one of 300 msec. So I have changed the function code to write to 1 register only and taken the delay out - we shall see how the Classic likes it now.....

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

WillEert

A form of success. I am writing to the Classic Battery Output Current Limit register and the Classic is not shutting down or rebelling in any way I can tell however -- The numbers the limit changes to do not make sense to me. I would have thought if I sent it 650 I would see     650 /10 = 65 however what I get is 88, which looks like the amp high limit. If I send it 65 I get 5 which looks like the battery low limit. So when I send it 300 I get.........5 ?????. Possibly this is a bit shifting thing although the register list does not show that this is type of byte.

More work needed.  I am baffled at this point I think.

At least my Classic has survived so far.

Latest sketch attached.

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

WillEert

Got it working - Yay. I know more about data arrays today than I did yesterday.

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

dgd

Will,
How have you progressed with this?
All working now?
dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand

WillEert

Hi David,

   I am working towards a combination voltage control / amps control diversion controller. This control will let me overarray my batteries while preventing them from getting too much current. The concept is to have a control that will monitor both current flow to the batteries and battery voltage. If the current flow to the batteries exceeds a setpoint then the controller will divert based on amps to the batteries. As the batteries charge and the current they take reduces then the controller automatically will change to do voltage control diversion.  Paul sent me all of his work with a diversion controller that has a gui but I have not had time to get it up and running as the amps /voltage controller has been consuming me.
   I coded up a method of changing the amps setpoint limit based on wbjr amps flowing to the battery. This lets me set the amp limit high (near comfortable Classic max) to bring as much power in as possible from the array. If the diversion load should not be available  (thermostats open) then the amps will rise above the amps diversion setpoint. When this happens the code reduces the amp setpoint limit to protect the batteries and vice versa. This is working very well.
   Next I got amp diversion control working. The amps to the battery really move around so I had to put in a smoothing system and control from that. Control is not that great due to smoothing time delay but  the concept works and will work better with some more tuning. The PID tuning is very different to the voltage tuning so I put in another PID controller for amp control with different tuning parameters - much slower.
   Next I started working on changing the state of the controller from amp control to voltage control based on input variables to the PID and amps in relation to the amp- setpoint. I had to put in a timer to prevent cycling between amp / voltage modes - this due to the slowness of amp control. Somewhere along the way I learned about pointers and am using them during the changeover process. I  have logic problems with the changeover and am working to resolve this. My most recent book is helping me with this. I realize that my logic was giving an if function a value of one when I am trying to compare values so it is making the statement true when it should not be. More thought required.
    While all this was going on I got into unreliability issues with the diversion controller. On 4 occasions the battery voltage variable locked up at one voltage. This caused the diversion controller to either go wide open or shut down - Yeek!!! What to do? I suspected possibly the uno had run out of memory as it was showing 64% when compiled so I started using a Mega. This was not the solution as it locked up with the Mega also. I started thinking it was the rs232 so read and learned more about how it worked. I increased the time out count ,polling time and number of retrys. I coded up a method of seeing the retry count and watched it. The sketch still locked up even though the rs232 was OK. Hmmmm.....
      I went back to a very simple voltage control diversion sketch. This worked very well and did not lock up. I started adding refinements a couple of days apart. When I added the "button'" I had coded up to turn off the lcds with a time delay the controller locked up. I took the button out and have not locked up since. The button turns the lcds on when pushed and then after a millis count turns them back off again - similar to the Classic controller which we like so well. I am going to run with no changes for another 2 weeks before I go at the amp control again just to be sure that it was the button that was giving the controller the reliability issues.
      So that where I am. We are building a house and we are pushing to get in before Christmas. I have not figured out why my button locks up the voltage variable - an overflow or something perhaps. Luckily I do not need it to run the control. I coded up a simple system that turns the lcds off when the Classic is resting which is better than having them on all the time but it is not really how I want the controller to work. So I am thinking now  a state machine will work well to change modes. I think with my new understanding that any number greater than one is seen as true in an if statement will let me get the changeover logic working as I would like. I am still poking about with different button logic as I would like the off delay timer to work. The pid voltage diversion controller is working great. I have tuned it up a bit more and now the response time to recover from a cloud and get back to full diversion is getting quite fast. Paul's idea of lead/lag elements is working well. I rewired my hot water tank and put new thermostats on it and my system now will capture just about every watt available so long as I do not run out of diversion load room. When I put the house heating system in service (which removes heat from the HWT via an hx) then the thermostats never open and my off grid system makes almost as much power as a grid tie system would.
      I am thinking it would be very easy to make a standalone amps diversion controller. I am considering doing this and running it for a while just to see how it works and to gain experience with it. It could then be added to the voltage diversion control and the state change logic figured out without the variable of trying to get the amp control working at the same time as trying to get the state changeover working. Also I am thinking of a amp limiting control to answer to need of some people on the wbjr thread. This would just raise and lower the amp limit within upper and lower parameters in response to amp flow to the batteries. It would not do diversion but would permit over arraying of a battery bank while protecting them from the risk of overcurrent - I think this should be quite easy.  I just need to get this house finished...

  Just for fun I have attached a sketch that is about as far as I have got when I had to back up and find out why the voltage was locking up. Caution - This is not a finished piece of code and will "lock up" periodically doing various horrible things to your system. Also the changeover logic is not working - I think due to the 1s problem. Maybe you can tell why the button timer gives the sketch problems - I have not been able to yet in the time I have had available to think about it.

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

Manjunath

I am also trying to read one of the Energy meter's modbus data through rs485 and show in hercules(Terminal).
for this case I used arduino as master to read Energy meter as slave to read modbus data. I am failed to use this library
Any body please help me