View Full Version : DIY Software
soakes94
01-29-2012, 08:19 AM
I was wondering if someone could help me out, I have some code that listens to my twitter, and when I tweet it reads the tweet. I have a list of commands in the software and if the software reads that a tweet it carries out a command. So lets say I tweet "Play music" it starts playing my music.
I had an idea of being able to control my central heating using this system so that maybe I'm away on holiday for 2 weeks and so switch the central heating and hot water off but want to be able to switch it on before I leave to come home so that the house is warm (I live in Scotland) and the hot water is hot.
My plan was to maybe use a PIC16F688 and some relays, what I need help with is outputting data out my com port to switch the channels on. So it would be something like
If Tweet = "Heating on" then
comport2.Channel 1 = High
End If
Line 2 is the line that will cause me problems since as of yet I dont know how to send data out of a comport and what data to send.
Im using VB 2010 Express.
derekbackus
01-29-2012, 08:32 AM
Have you seen phidgets.com ?
They have a bunch of different devices that interface with the world that are already made and have API to interface with them from any number of programming environments.
Not Renard or DIY, but quick and simple -- and not too expensive.
frankv
01-30-2012, 04:27 AM
My plan was to maybe use a PIC16F688 and some relays, what I need help with is outputting data out my com port to switch the channels on. So it would be something like
If Tweet = "Heating on" then
comport2.Channel 1 = High
End If
Line 2 is the line that will cause me problems since as of yet I dont know how to send data out of a comport and what data to send.
Im using VB 2010 Express.
Essentially, you need some hardware like the Renard board that many people here use... this receives messages via RS232 and turns on/off 230V devices. In our case, the device we're turning on/off is usually something like a string of lights or LEDs which is relatively low power (1 amp or less). If you want to switch high-power devices (e.g. heating) you'll need to replace the solid-state relays with actual relays.
To send commands to a Renard board, you send a message using the Renard protocol. If you build your own Renard-like board with your PIC and relays, you can decide your own protocol.
soakes94
01-30-2012, 11:50 AM
My plan was to design my own PCB using the PIC16F688 as the brain as I have no expereince in writing firmware but I understand how the renard boards work. So all I'm really looking todo is to be able to send the correct commands to the PIC from my own program. The bit I'm stuck at is sending data out a com port and what I need to send to make the pic do stuff.
Thanks
Steve
LabRat
01-30-2012, 12:40 PM
So the question is.. "How do I open up a COM port in VBasic, so that I can send commands over serial to the PIC".
I'm not a VB programmer so can't help too much, but sticking "vbasic how to open a com port" into google resulted in numerous hits, the top one of which was:
http://www.control.com/thread/1026198113
Which I think does cover what you are attempting to achieve.
soakes94
01-30-2012, 04:37 PM
Thanks for the link :) my next question is once its open what do I send through the com port to make the pic do stuff?
Steve
kychristmas
01-30-2012, 05:10 PM
Thanks for the link :) my next question is once its open what do I send through the com port to make the pic do stuff?
Steve
That's up to you. Sounds like you are developing your own board, so you will decide the standards. As for your own Firmware, I would suggest you take a look at some of the Renard Code. It has all of the pieces you are looking for and would be a good start.
LightUp
01-30-2012, 05:13 PM
It's difficult to precisely say.
I understood that you want to use a pic but you don't know how to program the firmware. Without knowing what firmware you are going to use one can't answer your question. If there is an existing firmware you want to use then you need to know if such firmware accepts a command(s). Or you need to know the protocol you will be using with sufficient detail to format your "SEND" data in that protocol's syntax.
soakes94
01-30-2012, 05:29 PM
I'm going to be using the pic16f688 with the renard firmware. So all I need to know is how do I tell the pic to turn on output 1 and turn it off and the same for the other 7 channels. I seen this page http://doityourselfchristmas.com/wiki/index.php?title=Renard where it talks about stuff but it confused me a bit.
Steve
LightUp
01-30-2012, 05:41 PM
OK, that is a bit clearer. This then also means that you will be using the same schematic as the Renard so that the firmware corresponds to the proper hardware inputs and outputs. I thought you were developing your own version with your custom firmware.
Since I don't know the Renard firware, nor protocol I can't guide you directly. Studying the Renard protocol will tell you what channel is to turn ON or OFF. The data you send from say VB will be formatted as per Renard protocol.
carlk
01-30-2012, 06:29 PM
I would try sending 3 sync bytes - 7E (126)
an ID byte - 80 (128)
and 8 data bytes - FF (255)
and see if it works.
This should turn on the first 8 renard channels
Carl
soakes94
01-31-2012, 02:55 PM
Well I've thrown together a small test program so I can see what happens when I send different commands to the com port. Just to check, does this look right?
SerialPort1.Write("7E (126)")
SerialPort1.Write("80 (128)")
SerialPort1.Write("FF (255)")
I have the port alread chosen in another part of the program but those lines are sent when I press a button. I put each peiece of code in a seperate transmit, is this right or should I transmit it all at once like this
SerialPort1.Write ("7E (126) 80 (128) FF (255)")
I need to get a proto board sorted with some LED's. I've got one set up for DMX but not renard. I will post the outcome here when I find out.
Steve
LabRat
01-31-2012, 03:10 PM
WIKI + Search + keyword "Protocol" :biggrin2:
http://www.doityourselfchristmas.com/wiki/index.php?title=Renard#Protocol
That being said, I doubt that your sample code is going to work. In most languages that I've run across,
the "" characters denote a string. As such I suspect your write of "7E (126)", would actually send 8 characters "7", "E", <space>,"(","1"... etc.
I would guess that you would want SerialPort1.Write(0x7E);
I'm not a VB expert, nor do I play one on television. I could be completely wrong on this front. That beind said I heartily recommend that you find some "introduction to VB" sites, and get a little bit more familiar with (pardon the pun) the basics of programming.
Well I've thrown together a small test program so I can see what happens when I send different commands to the com port. Just to check, does this look right?
SerialPort1.Write("7E (126)")
SerialPort1.Write("80 (128)")
SerialPort1.Write("FF (255)")
The above values were given in "hexadecimal" as well as the normal decimal equivalent for communicating with you as human; communicating with Visual Basic is different.
That is, 7E hexadecimal = 126 decimal.
You want to send one or the other as a number (not as text, often called a "string")
SerialPort1.Write(126)
or
SerialPort1.Write(&h7E)
The &h tells visual basic that you are using hexadecimal.
This is all pretty basic programming stuff, tho - if the above is not already familiar to you, there will probably be lots of other small gotchas, likely too many for the folks here to help with every one of them. I agree with LabRat - find some tutorials or a good book on Visual Basic (or specifically VB.net). Then the folks here may be able to help with the more specific quirks of Renard protocol etc. It's great that you are learning this tho and it can be a lot of fun!
soakes94
01-31-2012, 03:56 PM
I copied the program source code from an online tutorial so I'm guessing it will work, well so far it seems to. So when it comes to sending data I want to say
SerialPort1.Write(&h7E)
SerialPort1.Write(0x80)
SerialPort1.Write(255-FF)
I have experience with programming this is just my first time at sending data to a com port. This might sound like a stupid question but when I send data to the Renard PIC I'm assuming it has to be a certain peice of data. I read the wiki and I'm still slightly confused. I copied the data I'm sending from the wiki. Im not sure if it makes sense though or if I'm just being completely stupid here.
Steve
frankv
02-01-2012, 02:27 AM
I have experience with programming this is just my first time at sending data to a com port. This might sound like a stupid question but when I send data to the Renard PIC I'm assuming it has to be a certain peice of data. I read the wiki and I'm still slightly confused. I copied the data I'm sending from the wiki. Im not sure if it makes sense though or if I'm just being completely stupid here.
The comms world is a bit different from the regular programming world.
You need to send commands in the language that your recipient understands. This 'language' is called a protocol, and is carefully designed to allow the right kinds of data to be sent, and to allow for error detection and recovery.
In the case of the Renard system, data is sent in groups of 8 bytes, each of which represents the brightness of one channel... 0 is off, 255 is full on.
A single comms channel may have several Renard devices listening to it, so you need some way to identify which board the data is being sent to. The protocol does this by sending the number of the device just before the data. For no particular reason, the device number is sent as a byte with the most significant bit set. Devices are numbered from 0 to 127.
To overcome a spurious character on the comms line, you precede the device byte with another byte, with value 126 (7E). Whenever a Renard device receives 7E, it throws away anything it has previously received and waits for the device number.
So if a Renard device receives a sequence 7E 7E 7E 80 10 20 30 40 50 60 70 80 it throws away the 7E, treats the 80 as the device number (device 0) and then the next 8 bytes are treated as data. So this sequence of data would turn on the 8 channels of device 0 to the 8 levels specified.
soakes94
02-13-2012, 08:03 AM
I fiannly got it working :) Thanks to everyone who helped out.
For anyone else that is wanting to know how I did it, I used the following lines of code when sending the data:
Dim BufferOn() As Byte = {&H7E, &H80, &HFF, &HFF, &HFF, &HFF, &HFF, &HFF, &HFF, &HFF}
SerialPort1.Write(BufferOn, 0, 10)
If anyone wants a copy of the code or the program drop me a PM.
Steve
LightUp
02-13-2012, 10:39 AM
That's good news!
I'm glad you stuck with it to see your breakthrough. That's how tough problems are solved.
It's also a good educational process.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.