Contents
|
CodeThe code that you need to install is split into two parts:
293ea05d05e2ff2b35fdfdfbaae2298642018ccc7f7595c77d7791294df00420 *SubredditStatsMonitor-v1.00.00.00.zip e7ad03230350c050cbbb53e1308264529908535a2f8a775c458477e2818beb86 *SubredditStatsMonitor-v1.01.00.01.zip a22dbb51813d72e0442a828068ce7c39904b7d591b2387edd5a531e89af0855f *SubredditStatsMonitor-v1.02.00.00.zip Version history:
Setting Up
To use this project, you will need a copy of Python 3.
Arduino setup.After unzipping the download, simply open up the Arduino project in the SubRedditStatsMonitor folder. You should see the project open with five tabs. If you are using a LED module that is similar to mine, you can upload the project in the usual way. If you are using the 2 line LCD module, then you will need to make a minor change to the code as described in the important note on the wiring page. If you want to test the Arduino code after uploading (which is a good idea):
Python setupThe Python script obtains data from a server and passes it to the Arduino for display. If the Python script is not running, then (this version of the Arduino code) has no way to get up to date data. The Arduino will simply continue to display the last set of values that was given. Note that this is a one time setup. You may need to vary this to suit your existing environment. For example, if you have Python 3, but not pySerial, then you will likely only need to do step 3. To prepare to run the Python script, you will need to do the following:
Run the Python scriptOnce you have the Python environment setup, you can run the script as follows:
If you are running on Windows, then the command might look like this (assuming the Arduino's port is COM8): python redditGetSubredditStats.py COM8 115200If you are running on Linux or Mac, then the command might look like this (assuming the Arduino's port is /dev/ttyS7): python redditGetSubredditStats.py /dev/ttyS7 115200
The default is to collect statistics from r/Arduino. You can nominate an alternative
by providing the subreddit name on the command line as the third parameter.
python redditGetSubredditStats.py <PORT> 115200 ArduinoProjectsWhere <PORT> is the port assigned to your Arduino (as reported in the IDE). Do not specify the "r/" as part of the name. Note if running under cygwin, you may encounter an error such as either of both of the following: termios.error: (22, 'Invalid argument') serial.serialutil.SerialException: Could not configure port: (22, 'Invalid argument')If you experience this, try openning up a DOS command prompt and enter: mode COMn 115200where n is the port number corresponding to the cygwin Serial port name. This is usually one higher than the cygwin number as cygwin starts counting ports from 0, whereas windows starts at 1. For example, if your arduino is assigned to /dev/ttyS7, then the correct command would be: mode COM8 115200. Once you have done this, try running the python script again. Adding a new display typeIf you need to add a new display type or want to add Ethernet support, review the rest of this topic then check out one or more of the following instructions: Currently these are Works in Progress, so not all of them are in place. If any of these are of potential interest, send me a message on Reddit - u/gm310509. The following diagram shows the software architecture of the project.
What the diagram shows is that the Monitor (the main Arduino program) defines a Subreddit Stats Object. This is named subredditStats in the program. The Subreddit Stats class defines a set of functions that do not have any code behind them. These functions relate to displaying data on a display that is yet to be defined. You can find these functions listed in the class definition. They are named:
The Subreddit Stats class is then subclassed (a.k.a. refined) by the various display drivers such as SubredditStatsLCD(). These subclasses implement (provide code for) the above functions. The code in these functions outputs the data in a way that works for that particular type of device. For example, the updateDisplay is called frequently to support rolling displays like the LED and 2 line LCD displays. It is also called once when new data is received. This is intended for displays such as the TFT panel which can display all of the information on a single page. An argument is provided to indicate whether the invocation is the regular update or new data update. As a result of this design, it is easy to add different display types to the program. To do this, we simply define a new class that refines the SubredditStats class and provide code for the above functions. Finally, the main program simply needs to define the subredditStats variable and the rest of the program should work without any change. For example, if we called our new class SubredditStatsTFT, we would add the following variable declaration in the main program: SubredditStatsTFT subredditStats = SubredditStatsTFT();
Another interesting point is that because there is a close relationship between the display and the
base statistics, it is easy to access the underlying data from within the display classes. The actual
statistics sort of form part of the display code, but are also kept isolated from it.
What this means is that the maintenance of the statistics can be done in isolation and without affecting
the display (or main program) and the display code can do its own thing irrespective of how the metrics
are maintained.
|