Difference between revisions of "SmartTerminal for Controlino"
Russ hensel (talk | contribs) |
Russ hensel (talk | contribs) |
||
Line 93: | Line 93: | ||
= Automation = | = Automation = | ||
− | Here we will automate the above. This is done by creating a class called ControlinoProcessing in co_processing.py and inserting/editing the code. To make this easier we will copy another processing unit of code. Copy gh_processing.py and save as co_processing.py | + | Here we will automate the above. This is done by creating a class called ControlinoProcessing in co_processing.py and inserting/editing the code. To make this easier we will copy another processing unit of code. Copy gh_processing.py and save as co_processing.py ( I have done some of the work here, you can start from a copy of co_processing_bak.py ) |
Back to parameters.py | Back to parameters.py |
Revision as of 15:54, 29 January 2017
Contents
What
This is part of the Instrumentino/Smart Terminal Challenge. In this part I am going to try to adapt the SmartTerminal ( PC/Python ) Python Smart Terminal to the ( microcontroller ) Controlino program Controlino Notes.
First Connection
Here we will just try to establish a basic connection between the two programs, typically this involves matching the communications parameters. Baud rate is, perhaps, the most basic.
Steps:
- go to Controlino program find baudrate #define SERIAL0_BAUD 115200
- go to SmartTerminal parameters.py and define a new mode Controlino: ( this code is near the top of parameters.py and you will see a bunch of modes defined there, likely with several comented out, remember the lats value set is the one that wins. Your code should then look something like:
self.mode = "GreenHouse" # add sensor processing, monitoring and logging for greenhouse sensors # self.mode = "IR" # self.mode = "MotorDriver" # special buttons, send arrays for motor controller arduino self.mode = "Controlino" # define mode for Controlino
- defining a mode is not really needed but this way it is easy to turn on and off the Controlino settings.
- find self.baudrate and add at end of baud rate section
if self.mode == "Controlino": self.baudrate = 19200
this way of setting the baud rate will only be in effect for the mode Controlino which, for now, we will implement as a straight terminal
Install Controlino on your arduino and fire up both the SmartTerminal and the arduino. Open the port and send "set" the arduino responds with "done", the eagle has landed.
Add strings for commands to interface
- look at the bottom of the C program and extract the following commands: "Set", "Controlino", "BlinkPin", "Read", "Write", "SetPwmFreq"
- find the section in Parameters ( in parameters.py ) that looks something like:
elif self.mode == "MotorDriver": self.send_ctrls = [ ...
and add a clause to the if then section like:
elif self.mode == "Controlino": self.send_ctrls = [ "Set", "Controlino", "BlinkPin", "Read", "Write", "SetPwmFreq" ]
note that this is just setting self.send_ctrls to a list of strings.
Run the SmartTerminal again, this time you will find the above commands loaded into the first several send areas as defaults. Try them out, all but "Controlino" respond with done. Invalid commands also seem to get no response. These commands look like they are supposed to have numbers appended as well, it would be nice if we had some values in place just to let you know what the expected form is.
Try Blink
- Blink using BlinkPin looks like it might be easy to use and test so lets look at it.
- the command seems to link to cmdBlinkPin(argV) and searching on it we find
void cmdBlinkPin(char **argV) { blinkingPin = strtol(argV[1], NULL, 10); blinkingDelayMs = strtol(argV[2], NULL, 10); pinMode(blinkingPin, OUTPUT); blinkLastChangeMs = millis(); startBlinking = true;
This in turns suggests the command "BlinkPin 5 300" will blink pin 5 with a delay ( half period or full period ) of 300 ms. Looking at my board it is very easy to put in a led on pin 7 so lets try "BlinkPin 7 300" as a command.
Back to
elif self.mode == "Controlino": self.send_ctrls = [ "Set", "Controlino", "BlinkPin", "Read", "Write", "SetPwmFreq" ]
lets change it to
elif self.mode == "Controlino": self.send_ctrls = [ "Set", "Controlino", "BlinkPin 7 300", "Read", "Write", "SetPwmFreq" ]
and running SmartTerminal again try the button for "BlinkPin 7 300" and it works.
Try Blink More
Looking at Controlino code I do not see any way to turn of the blinking ( beyond a reset ) "BlinkPin 7 0" might be a way to implement it. So what I will try to implement is a program that runs blink at 250 ms for 30 seconds then at 1000 ms for 30 sec and then repeats forever. First lets put the 2 commands on 2 buttons:
elif self.mode == "Controlino": self.send_ctrls = [ "Set", "Controlino", "BlinkPin 7 250", "BlinkPin 7 1000", "Read", "Write", "SetPwmFreq" ]
Run the SmartTerminal again, open the port and try the two buttons, they work for me, but this is not really automated.
Note if you have set up the SmartTerminal with a parameter for text file editing ( see: .... ) you can edit the parameter file with the <Edit Parms> button in the terminal, save the file and then restart the SmartTerminal with the new parameters by pressing <Restart> button.
Automation
Here we will automate the above. This is done by creating a class called ControlinoProcessing in co_processing.py and inserting/editing the code. To make this easier we will copy another processing unit of code. Copy gh_processing.py and save as co_processing.py ( I have done some of the work here, you can start from a copy of co_processing_bak.py )
Back to parameters.py
- Find the section containing
elif self.mode == "GreenHouse": print( "parameter says GreenHouse" ) self.ext_processing_module = "gh_processing" self.ext_processing_class = "GHProcessing"
and add a section in the "if then" like
elif self.mode == "Controlino": print( "parameter says Controlino" ) self.ext_processing_module = "co_processing" self.ext_processing_class = "ControlinoProcessing"
- Now lets edit the new co_processing.py:
- Find
# ================= Class ======================= # class GHProcessing( abc_def.ABCProcessing ):
and change it to
# ================= Class ======================= # class ControlinoProcessing( abc_def.ABCProcessing ):
Run the terminal again. It should run fine with some new buttons just below the <Open> <Close> ... buttons that have been around all along. Our job now is to modify the buttons and the code behind them.
Back into co_processing.py:
- GreenHouse Processing is fairly complicated, this is fairly simple so first we will rip out a lot of code:
- since so much code will go this is a list of the methods you should keep:
- __init__
- add_gui
- set_time
- find_and_monitor_arduino
- cb_find_and_monitor_arduino
- cb do_end_helper
- send_rec -- russ move to helper
- keep the class ButtonAction