This is an update to my FLiP Connect X-Mas Ornament project. For this update I have added a second RGB board for a second Ornament, added a Parallax 96x64 OLED Display Module for a Snowman graphic, and configured Flask on a Raspberry Pi to control the RGB colors remotely from a Browser.
One of the unique features of the Parallax Propeller Processor that is on the FLiP is that has what Parallax calls multiple Cogs. This is sort of like multicores, but each Cog is a bit more independent where each cog is given processing time by the Propeller Hub. When code is run on a separate cog, the processing of this does not affect code that is running on other cogs or the default cog 0.
More information can be found at the following:
https://learn.parallax.com/tutorials/language/propeller-c/multicore-approaches
In my project, I am running the code to control the Snowman display on the OLED using cog1 where the reset of the code that controls the Bluetooth and RGB processing is run on the default cog0. When a command is sent to the FLiP via the Bluetooth module, this does not interfere with the code that is running the OLED on cog1 so the animated display continues to run without any interruptions. Another unique feature of the Parallax Propeller is that it does not use Interrupts to perform this multiprocessing, so the Processor does not get interrupted when a command is processed from each Cog. This is another reason the Display is not affected by the Bluetooth connection and RGB processing.
In the SimpleIDE C code, to set this up, I added definitions for the stack size and a pointer to a cog that is used to control the function that the new cog will run:
unsigned int stack[128]; int16_t *cog; void snowBalls();
To start a cog with the associated function, the "cogstart" or "cog_run" routine can be used. I my example I used "cogstart"
// Run snowBalls routine in separate cog cogstart(snowBalls, NULL, stack, sizeof(stack));
Another feature I added was the ability to control the RGB colors remotely using a Browser from a PC or a mobile device. I configured Flask on a Raspberry Pi to add this feature.
A good place to get started with Flask is a Flask tutorial:
http://flask.pocoo.org/docs/0.12/tutorial/
in my example, the first step was to create a run.py file which acts as the launching point for Flask:
#!/usr/bin/env python from app import app if __name__ == '__main__': app.run(host='0.0.0.0', port=5000, debug = True)
A config.py was created for generic Flask configurations:
#!/usr/bin/env python # config.py class Config(object): """ Common configurations """ # Put any configurations here that are common across all environments class DevelopmentConfig(Config): """ Development configurations """ DEBUG = True HOST = '0.0.0.0' PORT=5000 class ProductionConfig(Config): """ Production configurations """ DEBUG = False HOST = '0.0.0.0' PORT=5000 app_config = { 'development' : DevelopmentConfig, 'production' : ProductionConfig }
Then a file, 'views.py', was created to accept command from the HTML code running in a browser and then send the command to my python script.
#!/usr/bin/env python from flask import Flask, request, redirect, render_template from app import app import procTest #app = Flask(__name__) @app.route("/") def index(): return render_template("index.html") @app.route('/signup', methods = ['POST']) def signup(): ledstate = request.form['ledstate'] #cmd = "procTest.py " + email #os.system(cmd) procTest.main(ledstate) print("The LED Color is '" + ledstate + "'") return redirect('/') @app.route('/buttonTest', methods = ['POST']) def buttonTest(): #ledstate = request.form['ledstate'] #cmd = "procTest.py " + email #os.system(cmd) procTest.main('RED') print("The Button Was pressed'") return redirect('/') if __name__ == '__main__': app.run(host='0.0.0.0', port=80, debug = True)
The HTML code used was just to show a submit option as well as a button to set the Red LED.
<!DOCTYPE html> <html lean="en" data-ng-app> <head> <meta charset="utf-8"> <title>FLiP RGB Ornament</title> </head> <body> <p aign="center"> <form action="/signup" method="post"> <div> <input type="text" name="ledstate"></input> <input type="submit" value="Set LED"></input> </div> </form> </p> <p> </p> <p aign="center"> <form action= "/buttonTest" method="post"> <div class="button"> <button type="Test">Set a LED</button> </div> </form> </p> </body> </html>
I'm still working with this to get a better display from the browser, but thus far it seems to work.
With these updates, I can send a command from a browser to the FLiP circuit. Also, the OLED displays the Snowman graphic at the same time.
This is video showing these updates
Since the OLED was not very visible in the previous video, I created a separate video to show the OLED display although it is not perfect.
That is all I have for now. Still need to get these in a case and hung on the ole tree.
Cheers!