Announcement

Collapse
No announcement yet.

Arduino Script Testing. (Enigmatheatre)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Here is my progress so far. I have the arduino communicating to a terminal program via Xbees. Have garbage at 115200 but at 57600 it works great. Now if I can only slow the baud rate to 57600 in the homeseer plugin I am in like flint. It is sending temperatures just fine.

    I will try to use the HS3 plug at some time but I need to interface a Ph sensor using software serial and try to transmit like a one wire sensor for the time being. At least making some progress. This will be a pool monitor to monitor the ph, pool temp, and the solar panel heating system. Next???? I'll dream of something.

    Dave

    Comment


      UPDATE: I managed to get the Ph sensor to work and sent out the RF1. I set it for 115200 and connected it to HS2. It doesn't see it. I am not surprised though. Must be some format that the plugin needs to create a device. Any way still plugging at it.

      Comment


        Originally posted by gdyrdave View Post
        UPDATE: I managed to get the Ph sensor to work and sent out the RF1. I set it for 115200 and connected it to HS2. It doesn't see it. I am not surprised though. Must be some format that the plugin needs to create a device. Any way still plugging at it.
        Not wanting to step on enigmatheatre's toes here but it is relatively easy to get a script going to read data from an arduino and put it into some HS devices. I put a couple of DHT11's and an I2C UV/light sensor in yesterday and the script is not that complex, splits up the serial data from the arduino and then sets some HS devices.

        Comment


          Thanks Mrhappy. My scripting is very rusty these days. Can you give me an example of one that receives data from the com port and parses the data and creates a device for it if it does not exist. It might jog my memory. Data is sent 57600 no parity in the same format as Enigmatheater's sketch. I still won't give up on his use but wouldn't mind getting data from this for the time being. Any help will be appreciated.

          Comment


            This is a simpler one that I am using that reads 8 digital inputs from my Alarm panel. The script on the Arduino just throws the data out of the serial port in the format "#0:0:0:0:1:1:0:0" representing D2 to D10.

            Code:
            Dim DC As Byte = 25
            Const HC As String = "W"
            Const LT As String = "AlarmIO"
            Const PN As Integer = 11 'this is the port number
            
            Sub Main(ByVal Parms As Object)
            
                Dim RecData As String = Parms.ToString
                If hs.ison("Q13") Then my.computer.filesystem.writealltext(hs.getapppath & "\data\debug.csv", now() & ", AlarmIO," & parms.tostring & vbNewLine, True)
            
                hs.setdevicestring(HC & (DC + 8), Now(), True)
            
                Dim ArData() As String
            
                RecData = RecData.Replace("#", "")
                ArData = RecData.Split(":")
            
                For i As Integer = 0 To ArData.GetUpperBound(0)
                    If ArData(i) = "1" Then
                        hs.setdevicestatus(HC & DC + i, 2)
                    ElseIf ArData(i) = "0" Then
                        hs.setdevicestatus(HC & DC + i, 3)
                    Else
                        hs.setdevicestatus(HC & DC + i, 17)
                    End If
                Next
            
            End Sub
            
            Sub Watch(ByVal Parms As Object)
            
                Dim TS As New TimeSpan
                ts = DateTime.Now - Convert.ToDateTime(hs.devicestring(HC & (DC + 8)))
            
                If TS.Minutes > 5 Then
                    Log("Data Has Not Changed In Five Minutes")
                    hs.setdevicevalue(HC & (DC + 8), 1)
                Else : hs.setdevicevalue(HC & (DC + 8), 0)
                End If
            
            End Sub
            
            Sub OpenP(ByVal Parms As Object)
                hs.closecomport(PN)
                Log("Port Close Attempt")
                hs.waitsecs(2)
                Dim ReplyStr As String = hs.opencomport(PN, "9600,N,8,1", 1, "alarmIO.vb", "Main")
                If ReplyStr IsNot "" Then Log("Reply:" & replystr)
                Log("Port Open Attempt")
            
            End Sub
            
            Sub Log(ByVal Data As String)
                hs.writelog(LT, Data)
            End Sub
            
            Sub CDevices(ByVal Data As Object)
            
                Dim objDevice As Object
                For i As Integer = 1 To 9
                    If hs.deviceexists(HC & DC) <> -1 Then
                    Else
                        If i = 9 Then objDevice = hs.NewDeviceEx("AlarmIO Status") Else objDevice = hs.NewDeviceEx("AlarmIO Input " & i)
                        objDevice.location = "AlarmIO"
                        objDevice.hc = HC
                        objDevice.dc = Trim(Str(DC))
                        objDevice.misc = &H10
                        objDevice.dev_type_string = "AlarmIO Input Device"
                        hs.SetDeviceStatus(objDevice.hc & objDevice.dc, 3)
                        Log("Creating Device: " & HC & DC)
                    End If
                    DC += 1
                Next
            End Sub
            I run the CDevices function once to create nine devices (eight inputs and one status that holds the date/time of the last update, just used to watch whether or not the port is still connected because I am using Bluetooth serial devices).

            When HS starts I run the "OpenP" function that tries to open the COM port at the specified baud rate, giving the function that is called when serial data arrives.

            When the serial port gets a new line it runs the Main routine, I remove the first "#" and then split up the remainder of the line by the colon. Testing the bit between the respective colon I then set a device on/off. I have another device that is a temperature sensor also using Bluetooth serial transceivers, the script is mostly the same except the Main routine just converts the parameter into a value for temperature and sets a device.

            Code:
            Sub Main(ByVal Parms As Object)
            
                If hs.ison("Q13") Then my.computer.filesystem.writealltext(hs.getapppath & "\data\debug.csv", now() & ", BlueTemp," & parms.tostring & vbNewLine, True)
            
                hs.setdevicestring(HC & (DC + 1), Now(), True)
            
                Dim CTempVal As Double = Convert.ToDouble(Parms.ToString) - offset
            
                hs.setdevicestring(HC & DC, HTMLStr & Format(CTempVal, "00.0") & " °C", True)
                hs.setdevicevalue(HC & DC, Math.Round(CTempVal, 2) * 10)
            
            End Sub

            Comment


              HI gdyrdave,

              I have dug out a backup of the script and compiled a new version but have not had time to test it.
              If backup your Arduino.vbn file and replace it with the one attached then add the line "Baud=" without quotes to the arduino.ini then set this to the value you require. It will default to 115200 if the script can not find this value in the ini.

              I hope this works for you.

              Greig.
              Last edited by enigmatheatre; April 25, 2014, 06:51 PM.
              Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
              X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
              Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
              Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
              Scripts =
              Various

              Comment


                Thanks Greig. I'll let you know.

                Dave

                Comment


                  I replaced the .vben file, edited the ini file added Baud=57600. When HS starts up I get an error that says Running script arduino.vben : method not found. here is the ini file:


                  [Settings]
                  Logging =0
                  No of Boards=1



                  [Board1]
                  Com port=15
                  Baud=57600

                  Board Address=1
                  Board Code=D1
                  No Of Inputs=0
                  No Of Analogue=0
                  No Of Outputs=0
                  No Of PwmOutputs=0


                  Lcd Width=16
                  Lcd Hight=2
                  Lcd Clear=1

                  RomAddress,2810D38C050000AB=D7
                  RomAddress,28E2218D0500001D=D8
                  RomAddress,28D9158D05000093=D9

                  Comment


                    Comment


                      More progress. I went back to the original vben file and configured the sketch for 115200. I directly connected it to the HS computer. Didn't see the Ph reading it was transmitting. So I changed the arduino sketch so the ph value was transmitted like the one wire devices. I changed the output string to transmit Rom instead of Ph1 and put an arbitrary Hex address field. Low and behold I have the Ph reading in Homeseer. Now if we can get the baud rate script working I am home free. Well for a while....lol

                      Mrhappy, I think I may have a use for your samples you posted.


                      dave

                      Comment


                        How do you write to an lcd. Event??? Script???

                        Comment


                          Originally posted by gdyrdave View Post
                          How do you write to an lcd. Event??? Script???
                          Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
                          X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
                          Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
                          Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
                          Scripts =
                          Various

                          Comment


                            Thanks Greig. I did not see that in the HS2 manual I have. I'll look again. Any idea about the error message on the version you sent me. I am testing it now with the earlier version at 115200 directly connected.

                            Comment


                              OK...Egg on my face...I found it in the manual. I guess I was too excited on getting the Ph to read into HS2. Sorry about that.

                              Comment


                                Originally posted by gdyrdave View Post
                                Thanks Greig. I did not see that in the HS2 manual I have. I'll look again. Any idea about the error message on the version you sent me. I am testing it now with the earlier version at 115200 directly connected.
                                Not to sure why the error is there I will see what I can do.

                                Greig.
                                Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
                                X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
                                Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
                                Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
                                Scripts =
                                Various

                                Comment

                                Working...
                                X