Author Topic: Beginners guide to hooking Classic to Arduino for serial  (Read 765 times)

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1860
I am going to document my adventures in trying wire Classic to get serial output for Arduino.

While I had the Classic open I connected wires on AUX 1 jack - was really difficult to get the stranded wire to slide in without bending strands so I gave up and uses pieces of solid wire and connected my stranded wires on those.




Larry
« Last Edit: May 26, 2018, 11:16:37 PM by ClassicCrazy »
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1860
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #1 on: May 03, 2018, 05:14:23 PM »
I used an ohm meter to check the pins on the jack and label the ends of the wires.  Good to verify and label to save headaches later !

Larry
« Last Edit: May 26, 2018, 11:17:27 PM by ClassicCrazy »
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

WizBandit

  • Guest
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #2 on: May 03, 2018, 06:03:22 PM »
When I get some time I will post some pictures of a working RJ11 to DB9 to RS232-USB cable I built.
Also you might want to read up on MODBUS commands, the CLassic supports fc-03 and fc-06 very well.
http://www.simplymodbus.ca/FC03.htm
http://www.simplymodbus.ca/FC06.htm

Use the middle jack.

You will want to grab this:
https://sourceforge.net/projects/qmodmaster/

And use it to test your cable.  It supports Serial RTU and TCPIP and I was able to read my Classic using both.
Caution on writing, you can let the smoke out writing to the wrong registers.
I would test using the Classic Name registers, 8 bytes starting at address 4209 (registers 4210-4213)

They contain the word "CLASSIC" and it will read like this "LC" "SA" "IS" "00C" because of LSB/MSB
Oh, and in HEX not ASCII.  The Name registers use "0" for BLANK

“CLASSIC” = 0x4C43, 0x5341, 0x4953, 0x0043
« Last Edit: May 03, 2018, 06:05:15 PM by WizBandit »

WillEert

  • Full Member
  • ***
  • Posts: 151
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #3 on: May 04, 2018, 04:42:33 PM »
I guess I cheated when I started trying to get serial communications to happen between the Arduino nd the Classic. I used a DFRobot rs232 shield so I did not have to worry about if the signal conversion was actually happening or not. I went to a mega after a while as that way I could put the Classic on one serial port and the usb on another. Much better.

https://www.robotshop.com/ca/en/rs232-shield-arduino.html?gclid=Cj0KCQjwibDXBRCyARIsAFHp4fqmwtlGP2GvnkljR7VFFxp5redEg_OpV8qam-EOhc_QPClSXmyEr-kaArlJEALw_wcB

I used this device

https://www.ebay.ca/itm/DB9-Male-RJ11-Adapter-23752-/391046835242?hash=item5b0c352c2a&_uhb=1

to go between the DB9 and RJ11 connection. By changing which pins went in which hole I could get the pinout needed.

Will

(1) 24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system;
(2) 15 Heliene 330 mono, Classic 150; (3) 2 X 6 Hansol 345 mono, 2 stand alone Hotspot ACDC12C Mini-split heat pumps.

WillEert

  • Full Member
  • ***
  • Posts: 151
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #4 on: May 05, 2018, 04:27:56 PM »
Hi Larry,

There are many libraries you could use for modbus. My sketches use the same one DGD used - SimpleModbusMasterV12. This library can be hard to locate so I have zipped up the one I have and attached it. The folder for this library needs to be renamed SimpleModbusMasterV12 when you put it into your Arduino library folder. I am not that familiar to the zipping process so hopefully this works.

Will
(1) 24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system;
(2) 15 Heliene 330 mono, Classic 150; (3) 2 X 6 Hansol 345 mono, 2 stand alone Hotspot ACDC12C Mini-split heat pumps.

WillEert

  • Full Member
  • ***
  • Posts: 151
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #5 on: May 11, 2018, 04:27:38 PM »
Hi Larry,

I spent hours getting my system to work. When it does you will feel very good. Here are my pinouts. Please be aware that in the Midnite document Midnite Solar MODBUS Network Spec Rev B.3 May 28, 2013 the pinout for the lower RJ11 port is NOT correct.

I use the lower RJ 11 jack as I have a remote MNGP connectted to the middle.

Lower RJ11 port

GND is pin 2, RX is pin 3 and TX is pin 4.    Midnite data shows TX pin 3 and RX pin 4.

Remember: Arduino is master, Classic is slave.
Master TXD connects to Slave RXD
Master RXD connects to Slave TXD


The colors are common to my wires. The logic does show how I followed my pinout through the system.

                 Classic      RJ11        Rs 232 BOB       Shield
Slave gnd:  pin 2       red 2         yellow 2            pin 5 Master Gnd
Slave TXD:  pin3       brown 3     green 3             Pin 3 Master RXD
Slave RXD:  pin4       green 4      red 4                Pin2 Master TXD

BOB Male DB9 pins order which connect to Shield female sockets. Lower row of the five pins in the DB9 connector shown

Lower row of pins: Left to right - Yellow (2) . empty, Red (4), Green (3), empty


Middle RJ 11 port

            Classic                     BOB                        Shield
RXD:     Pin 3                       Pin 3                       Pin2     TXD
TXD:     Pin 4                       Pin 4                       Pin3      RXD
Gnd:     Pin 5                       Pin 5                       Pin 5     Gnd

A common error is to connect RXD to RXD and TXD to TXD instead of RXD to TXD and TXD to RXD.

Hope this helps. I think you are not to far away from being successful.

Will


(1) 24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system;
(2) 15 Heliene 330 mono, Classic 150; (3) 2 X 6 Hansol 345 mono, 2 stand alone Hotspot ACDC12C Mini-split heat pumps.

WillEert

  • Full Member
  • ***
  • Posts: 151
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #6 on: May 11, 2018, 07:55:06 PM »
Hi Larry,

My cable is quite long. Even TTL voltage levels should go 25' I think and this is RS232 voltage.

I don't think your Classic is different than others.

I have only used the RS232 shield so I am not much help with the other hardware. When I was starting out I bought a few chips but I could not figure out the data sheets so went with the shields. I know DGD uses chips however so he could likely offer very good advice on this question.

Here is a picture of the Uno with shield and 4X20 LCD. The pinout changes in the BOB using the needed three wires only.
(1) 24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system;
(2) 15 Heliene 330 mono, Classic 150; (3) 2 X 6 Hansol 345 mono, 2 stand alone Hotspot ACDC12C Mini-split heat pumps.

WillEert

  • Full Member
  • ***
  • Posts: 151
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #7 on: May 12, 2018, 10:28:12 AM »
A possibility is that the RJ12 cable you have might not be a data cable (straight through) but a cable that crosses over. I can't tell by reading if you have tested for that or not. I have a RJ12 cable that I had to buck into and resolder the wires to get it to go straight through......Not pretty but it works.

Will
(1) 24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system;
(2) 15 Heliene 330 mono, Classic 150; (3) 2 X 6 Hansol 345 mono, 2 stand alone Hotspot ACDC12C Mini-split heat pumps.

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1860
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #8 on: May 26, 2018, 11:12:24 PM »
I finally got it working !!!
I deleted all my old posts where nothing was working the way I was doing it previously .
I ran a piece of Cat 6 cable that I had here - about 22 feet or so I think.
I put an RJ 11 connector on the Classic end - it only had 4 contacts instead of 6 but it plugs in and works because pins 1 and 6 are not used for the modbus anyway .
It is plugged into the lowest bottom jack of the Classic ( labeled Master In on Classic)
Classic End
Pin 1 - no connection
Pin 2 - ground    ( I used the white/orange wire of cat 6)  this goes to  pin 5 ground of Male DB9 connector
Pin 3 -  TX output  ( I used solid blue of cat 6) this goes to pin Pin 2 of the DB9 which is Receive  Data
Pin 4 -  RX input  ( I used white/blue of cat 6)   this goes to Pin 3 of DB9 which is Transmit  Data
Pin 5  - not used ( though I had connected solid orange of Cat 6 to it )
Pin 6 - no connection
Reference for above pinouts
Page 44 of Midnite Classic Modbus register document http://www.midnitesolar.com/pdfs/classic_register_map_Rev-C5-December-8-2013.pdf
DB9 pinouts https://www.lammertbies.nl/comm/cable/RS-232.html
I used Arduino Uno clone like this
https://www.ebay.com/itm/UNO-R3-ATmega328P-CH340-USB-Board-for-Compatible-Arduino-DIY/321871945148?hash=item4af1101dbc:g:2usAAOSwWnFV~-Ir
But I also have a Mega for future projects
https://www.ebay.com/itm/USA-SHIP-MEGA-2560-R3-Board-ATmega2560-16AU-CH340G-USB-Cable-for-Arduino/222252152478?hash=item33bf42b69e:g:oUMAAOSwzaJX3BV-
The RS232 board was my biggest source of frustration earlier  - I was trying to use the $2 RS232 to converters and nothing would work - spent way too many hours messing with it.
So I took Will's advice and bought an RS-232 shield - not the exact DFRobot one he has but one like it that has RS232 but also RS485 option . About same price - this is the one I bought
https://www.amazon.com/gp/product/B00N4MKVFK/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1
I have the small toggle switches in RS232 position and the other one in UART position ( note you may have to put it in Soft Serial position to load code into Arduino or unplug shield first ( I had it unplugged when I loaded code)
I am using an LCD Keypad shield for now and that is plugged into RS232 shield
This is keypad shield I am using
https://www.ebay.com/itm/1602-Serial-Blue-Backlight-LCD-Display-Keypad-4-Arduino-Uno-R3-Mega-2560-Shield/232356694187?hash=item361989c8ab:g:DxgAAOSwAPVZMD9f
If you shop around on ebay or Aliexpress you can get all the above parts for maybe half the cost if you don't mind waiting weeks to a month to get them. The USA suppliers ship them right out and get them in a few days .

So I have piggy backed Arduino Uno on bottom , then RS232 Shield , then LCD shield. Had to jiggle them to get all pins seated well to make everything work - and careful because it is possible to push bottom pcb board onto RS232 jack and short it .
I am using DGD's sample code for now but am planning on modifying it to scroll through different Classic readouts so I won't have to push the buttons on Keypad shield like with his code.   I will also modify code to get different readouts from Classic  than DGD has in his sample code.
http://midniteftp.com/forum/index.php?topic=2328.msg22014#msg22014

Thank you  Will for taking time to help me get over the hump on this ! And thanks to DGD for figuring out the Arduino code to make it work.

Larry

« Last Edit: May 26, 2018, 11:21:55 PM by ClassicCrazy »
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

Vic

  • Hero Member
  • *****
  • Posts: 2005
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #9 on: May 27, 2018, 02:35:22 PM »
Hi Larry,

Thanks for the play-by-play on this.

Great work!   73,   Vic
Off Grid - Two systems -- 4 SW+ 5548s, Surrette 4KS25 1280 AH X2@48V, 11.1 KW STC PV, 3X MidNite Classic 150 w/ WBjrs, Beta KID on S-530s, MX-60s, MN Bkrs/Boxes.  Thanks MN for Great Products/Service/Support!

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1860
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #10 on: May 27, 2018, 07:15:48 PM »
Hi Larry,

Thanks for the play-by-play on this.

Great work!   73,   Vic
Hard to get all the info on one place - so trying to make it a lot easier for everyone else - especially the pin outs and wire connections !

Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

WillEert

  • Full Member
  • ***
  • Posts: 151
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #11 on: May 31, 2018, 11:29:01 AM »
Congratulations Larry. I know when, after hours of trying, when suddenly (after I had lost faith but was too stubborn to stop) the lcd lit up with data I had this great feeling of accomplishment. Yay!!!. Likely you had a similar feeling. I am also very grateful to DGD as I know without his code example of how to read from the Classic I would not ever have started.

Possibly a "kit" composed of all of the equipment required and a pre-programmed Arduino would be a product that interested people would buy. Once you can read from the Classic then you can now configure your own control system. Very satisfying and empowering.

A great book for me, starting as complete coding beginner was "Beginning C for Arduino". I ended up with a library of Arduino books to help me learn. Three others I commonly use are Arduino Programming in 24 Hours (R Blum), Arduino Sketches (Langbridge) and Exploring Arduino (J Blum). With these four books how to do almost anything can be figured out.

Cheers and congratulations again.

Will
(1) 24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system;
(2) 15 Heliene 330 mono, Classic 150; (3) 2 X 6 Hansol 345 mono, 2 stand alone Hotspot ACDC12C Mini-split heat pumps.

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1860
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #12 on: May 31, 2018, 12:39:14 PM »
I have started looking at some of the Arduino code that you posted Will. It will take me awhile to understand the structure of all of it and then reuse the parts that I want to.
The first thing I tried to do was just change the Celsius temps to F
I tried plugging in a couple different formulas to the line
pcb_temp /=10;
with this
pcb_temp /=10*1.8+32;
or this
pcb_temp /=10 * 9 / 5 + 32
so far no success but it is fun trying and I am learning along the way .

Also I think somewhere earlier you had said that the pinout in the Midnite modbus document for the bottom jack was not accurate but I found it to be correct .

Thanks again for the help  - so many other projects going on now I just put a bit of time into this here and there. You certainly learned a lot quickly and absorbed all those Arduino books so now you can float - ha ha !
Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

WillEert

  • Full Member
  • ***
  • Posts: 151
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #13 on: June 01, 2018, 12:57:53 PM »
Hi Larry,

I was using a slightly older version of the Midnite Modbus document so maybe your newer one had the pinout corrected.

I have never been that successful coding a large mathematical formula. I usually take it one step at a time.
Consider:

pcb temp /=10;
pcb temp *= (1.8) + 32;

//-------------------------------------

or
pcb temp /= 10;
pcb temp *= 1.8;
pcb temp += 32;

Will
(1) 24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system;
(2) 15 Heliene 330 mono, Classic 150; (3) 2 X 6 Hansol 345 mono, 2 stand alone Hotspot ACDC12C Mini-split heat pumps.

dgd

  • Hero Member
  • *****
  • Posts: 1715
    • Lorylink
Re: Beginners guide to hooking Classic to Arduino for serial
« Reply #14 on: July 06, 2018, 07:51:32 PM »
Good job Larry and Will
Over the last 2 years I had quite a few enquiries from people interested in using an Arduino to display modbus data from a Classic. By far the most difficult issue for many was figuring out the serial cable.
Your articles here (faq) do that. Thanks

Dgd
« Last Edit: July 06, 2018, 07:57:53 PM by 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