Tagged: video

Hakology Project Notes : Python, RedditAPI, Arduino, RaspberryPi thing.

Over the last three weeks I’ve been playing with various breakout boards, microcontrollers and embedded linux. I’ve been trying to take time to learn how the technology works and how best to combine them to teach and produce something useful, different and entertaining. So this project initially started out when I was playing with the RTLSDR dongle, I thought it might be cool to display the messages as they got demodulated on a separate device that was dedicated to grabbing POCSAG messages, I slapped it all together, then when my son was over the other weekend we decided to modify the code to grab the top 25 articles from a given subreddit.

Eventually when I get time ill put together a video tutorial on setting this all up but in the meantime here are the notes …

You will need:

1 x Raspberry Pi model B.
1 x Wifi dongle or ethernet cable.
1 x Arduino deumilinove.
1 x USB lead (for serial communication with the arduino)
1 x USB lead (to power the RPi)
1 x USB Charger
1 x LED Matrix 8×8 x4 (I used the horizontal style layout)

So how does it work?
Its pretty simple really, the raspberry pi runs a small python script that grabs the top 25 articles from a predefined subreddit using the api (most of reddits api can be accessed just by post fixing .json to a lot of their URLS the data structures are also well documented and available on github.) The script strips out any weird characters as the JSON is returned in utf-8 format. A string is built containing the articles rank, total amount of upvotes and the article title. If the string is over 300 characters it gets trimmed and “…” appended to the end. The script creates a serial connection to the arduino (the device is usually addressable using /dev/ttyUSB0) The string is then sent to the arduino over serial. When the arduino receives a new string it displays it to the LED matrix after having scrolled any current messages.

What’s the python code?

Install and configure raspbian in the normal way. Before running the script make sure you have internet access otherwise the python script will fail when it trys to communicate with reddit. (todo: add better error handling.)
Python code – http://pastebin.com/shXyry5C
Copy the code in to a file called reddit.py to your home directory.
Edit the file so it points to the correct serial device.
nano reddit.py
If you’re unsure about the arduino serial port run
sudo ls /dev
Look for something like …
ttyUSB0
Edit the line in reddit.py where the serial communication is initialised ensure it matches the port for the arduino.
ser = serial.Serial('/dev/ttyUSB0','57600')
Save the file using …
ctrl+x
Make sure the file has execute permissions by issuing the following command …
chmod +x reddit.py
You can test the script by running it from the command line using the following command (*this needs to be run with superuser privs to access the serial port) …
sudo python reddit.py
Once you’re happy with the way the script is running you can make it autoboot with the pi by using the following command …
sudo crontab -e
If you are prompted which editor to use and are unsure use nano (option 2)
At the bottom of the file add the following line …
@reboot /local/bin/python /home/user/reddit.py
Save the file by pressing ctrl+x
Reboot and test your script is autoloading.

To display the messages on the matrix you’ll need to flash your arduino with a little code …

Wiring the arduino …
To connect the arduino to the matrix you will need to ensure you have the correct SPI pins as they differ between arduino boards the ones on the deumilinove are pins A4 and A5, A4 SDA and A5 SCL, you will also need to attach the CS (chip select) pin to pin number 13 on the arduino and also connect VCC to 5v and GND to GND on the arduino.

A4 to SDA
A5 to SCL
13 to CS
5v to VCC
GND to GND

(todo : will post a pic when i get time)

What’s the arduino code?
Arduino code – http://pastebin.com/pvkM2DUK
Copy and paste the arduino code in to your arduino IDE, you’ll also need to grab the md_max29xx library from git hub. (Download the zip file and unzip the files to your arduino IDE library folder usually /Documents/arduino-x.x.xx/libraries) This library is used to drive the LED matrix. Once you’ve installed the library you’ll have to specify how many matrices you are using in the arduino code. (How many LED matrix panels you will be displaying to my board had 4 8×8 LED panels.) Here’s the important bit though depending on what/where/who you bought your led matrix board from you might find you’ll have to edit way the arduino draws to the matrix otherwise you could be in for some very interesting results. This can be done in the md_max29xx lib folder. There are a few variables that define the matrix rotation and draw direction IE. right to left, left to right, top to bottom etc. You will need to play with these variables until you get the right combination for your matrix.

NB. When initially getting this running use the example grapicstest to make sure the leds are drawing as expected then flash the arduino reddit serial code once you have the library configured correctly.

Now all the hard work’s done
Once you’ve installed the library, edited the arduino code, updated the variables for the draw direction and successfully flashed the code, plug the arduino in to the raspberry pi and boot. There should be enough of a delay in the script to ensure the RPI has connected to your network before it makes its initial request.

If you have the arduino setup correctly you should see scrolling text on the matrix. “Waiting for serial data!” after a short while the rpi should connect and start displaying articles from reddit.

Concluding
Still yet to build an enclosure or decided how / where im going to use this yet but i’ve had fun making it. Initially getting the libraries setup and running correctly was by far the most frustrating part of this project writing / editing the code was pretty straight forward. There’s plenty of scope for improvement / modification too, if I get time I was thinking I’d get it to cycle multiple subreddits, but for the time being I’ve spent enough hours on this project.

NB. The original code running on the arduino was limited to 25 characters I’ve modified this to allow for messages up to 300 characters in length (the size of an article title from reddit) Since doing so some of the serial messages appear to glitch intermittently. I’ve been checking the code for errors but haven’t managed to pinpoint the problem yet. As far as I can tell the python code runs fine but there might be a problem when the arduino is receiving the serial messages. Possible solutions maybe change the baud rate and send the data slower or add a checksum. (*As suggested by advancednewbie) Example code an library for implementing a checksum. https://github.com/AdvancedNewbie/serialChecksum

IF YOU HAVE ANY QUESTIONS REGARDING THIS PROJECT PLEASE PUT THEM IN THE COMMENTS ON THE YOUTUBE VBLOG EPISODE AT THE TOP OF THIS POST.

Hakology Day 37 : Blog Entry

[1543]
Good afternoon hakologists, I’ve finally got the LED matrix ‘working’ I’ve managed to find one library that draws correctly to the screen, with a little bit of effort I think I could rewrite it for multiple matrices. Today I’m going to get a quick vblog together then later tonight hopefully record the SDR# video. Then we’ll take a look at multimon-ng and demodulating pager messages.

Need to send a massive shout out to gir, for sending hakology 2 RPi Zeros from the US as I couldnt get any at a reasonable price anywhere in the UK. Ridiculous considering they are made less than 50/60 miles from my house.
[/1543]

[0015]
Family stuff over, vblog recorded, introduction video for vblog channel recorded, vblog rendering, time to get the kettle on and make a brew, thinking I might have a look at an old netgear router I have, see if I can connect using those new USB2UART boards. If I’m feeling really productive I might even get the sdr# video done.
[/0015]

[0133]

[/0133]

Hakology Day 35 : Blog Entry

[1825]
Reflecting on the weekend, have been working on a few projects. One using the max7219 LED matrix driver, which I’m considering writing my own library for as everything i’ve tried seems to fail, I have it working and can address each LED individually but haven’t been able display anything useful ie. fonts or text effects … anyway that’s a work in progress. I turned my hand to configuring a small 1.3″ OLED screen someone donated a while back now I can see it was some kind of addressing issue in the code I initially got it running (there were 2 pixels columns on the far right filled with random bits and a couple of leading pixel columns missing) anyway its working now I noticed the version I was running was from the google code repo and checked github see if the project was still live and found some more recent libraries, installed those and that seems to have remedied the problem.
[1825]

[0023]
Managed to sort out a good method for screen capture in gnome3 debian jessie. Was having issues capturing the screen in a format I was able to get in to my editing suite. Inadvertently I found out that debian jessie has built in screencapture/screencast ability. Pressing shift+ctrl+alt+R, a small red dot will appear in a panel near your login/logout  panel to show if you are recording, files are automatically saved to your home videos folder, to stop recording just hit the keyboard shortcut again.

These files happen to be in webm format, I havent yet tried running the webm files through handbrake to see if I can convert them to mp4 as my editing suite doesnt natively support webm and one huge problem with the built in screencast is it only records my desktop and no audio. (Maybe I’m doing something wrong, would be easier to just use the built in screencapture)

So eventually my final solution was to record using kazam to mp4, this captured the video + audio, was even hoping I wouldnt have to transcode it again, but still the default format output by kazam isnt compatible with vegas, I then ran the files through handbrake and imported them and everything seems ok … now all the audio syncs with the video perfectly.

Its a bit of a mess/bodge job but it works, maybe if I get some time in future I might have a look see if its possible to edit the default screencast settings to capture audio+video and output to a compatible format preferably mp4.

NB. The default screen recorder only allows you to record for 30 seconds use the following line in terminal to change the maximum record time.
gsettings set org.gnome.settings-daemon.plugins.media-keys max-screencast-length 45
[/0023]

Hakology Day 12 : Blog Entry

[1521]
Kettle is on. Coffee to be made. So day twelve begins.
[/1521]

[1530]
Tunes turned to 11 … its Friday!
Operation pre-weekend tidy up has begun.
[/1530]

[1653]
Slow start, written up all the notes for the SDR# tutorial, might have a go at recording it later, need to clear some space in the garage for some new equipment arriving soon.
[/1653]

[1913]
Just had a little jam on my drums .. its been way too long. Great warm up for some FPS.
[/1914]

[2044]
Right time to do something productive.
[/2044]

[0103]
Uploading SDR# tutorial, writing up notes in to a new post.
[/0103]

[0200]

Really quick video showing you how to install and setup SDR# under windows.
Moving on to linux and gqrx next.
[/0200]

[0321]

[/0321]

 

Hakology Day 10 : Blog Entry

[1600]
Great sleep, late start, wish I’d stayed awake earlier but must have needed the sleep, feeling refreshed time to get busy. Recorded first audio for SDR EP yesterday, needs work but not bad for first try.
[/1602]

[1755]
Rewritten dialogue again reads a lot better now. Looking for other SDR projects and ideas. Still yet to see if I have multimon-ng installed on the netbook. Tasks for the afternoon.
[/1757]

[1808]
Not so random pictures for the day …


[/1828]

[1919]

Just cooking some food and getting ready to record.

Recommended SDR shopping list for up coming content …
RTLSDR – RTL2832(u) DVB-T+DAB+FM Dongle (£10-£15)
MCX MALE TO BNC FEMALE (for connecting antennas) (Approx £2)
AIR BAND (or similar) antenna (usually with BNC male connector) (£3-£10)
PC/LAPTOP – Preferably laptop for portability. (Varies lol 😉 )

[/1927]

[1949]
Recorded introduction to SDR episode but still not entirely happy with the take, have some RL boring stuff I need to do but will be back later this evening.
[/1950]

[2039]
Back, quick wash and shave and time to record the final take. *Fingers crossed.*
[/2040]

[2256]
Editing done, rendering video.
[/2256]

[2301]
mmmm coffee!
[/2301]

[0006]
Uploading.
[/0006]

[0100]

[/0100]

[0239]
Time to relax!
[/0239]

[0451]
Sleep required.
[/0451]

Hakology – Retropie steam controller setup guide

Notes to accompany the following video showing you how to setup and configure the steam controller for retropie. Tested and verified as working with python 2.7 on the rpi model B and rpi3 model B.

sudo apt-get install python-pip
sudo pip install libusb1
sudo pip install enum34
git clone https://github.com/ynsta/steamcontroller.git
cd steamcontroller
sudo python setup.py install
sudo nano /etc/udev/rules.d/99-steam-controller.rules
Add these lines :
SUBSYSTEM==”usb”, ATTRS{idVendor}==”28de”, GROUP=”games”, MODE=”0660″
KERNEL==”uinput”, MODE=”0660″, GROUP=”games”, OPTIONS+=”static_node=uinput”

sudo udevadm control –reload
sudo crontab -e
@reboot /usr/local/bin/sc-xbox.py start

Hakology Day 6 : Blog Entry

[15.31]
Really late night last night, time to get the kettle on and wake up. Need to do some shopping then I think ill look at re-recording the steam controller tutorial without the animations and just do a straight forward install video, I’m thinking that’s the best plan of action. Wasted too much time on this video and want to get busy with SDR and some other bits and bobs.
[/15.31]

[16.40]
RPI3 arrived whoot

[/16.40]

[20.20]

More info on RPI hardware and chips
[/20.20]

[20.31]
CHARGE EVERYTHING!!!!
[/20.31]

[21.06]
SSH sorted to the pi for screen cap. (Thanks for the tip luc)
[/21.06]

[00.26]
Rendering test footage.
[/00.26]

[00.56]
Rendering the actual footage, get in there! Hopefully uploading soon. Then time for a little relaxation as I need to be up early tomorrow.
[/00.56]

[1.20]
Uploading hakology video and rendering VBLOG.
[/1.20]

[1.40]
Uploading zee files.
[/1.40]

[2.44]
Retropie steam controller installation tutorial. Guide, blog post and script coming soon.

[/2.44]

[2.46]
Day six vblog.

[/2.46]

Hakology Day 2 : Blog Entry

[12.30]
Print(“HelloWorld!”);
Time for caffeine.
Plans for today … Try to complete operation tidy up and start operation garage floor space verification lol, make notes for a video later, decided on content for up coming videos and get busy.
[/12.30]


[12.50]
Just catching up on news and events, messaged a few people last week who I know are still using yahoo and got them to change their passwords. This week it looks like its dropbox users that need to update their passwords. Seems like more reputable sites are being hit with big hacks. DDOS attacks are getting bigger due to IOT vulns. might have a look at that if I get chance to waffle off a VLOG and its wikileaks 10th birthday apparently they are going to post some documents to celebrate, will keep my eyes on that too.
[/12.50]


[13.33]
Doing well so far things are looking tidy. Just posted a quick question on reddit regarding steam controllers and tonights video. Enjoying a well earned coffee break.
[/13.33]


[15.00]
Coffee time again, last one for a while I think, research is going well, encountered an issue configuring the steam controller on the raspberry pi, going to just try and work with the keyboard see how it goes. Much progress, I can see I’m going to have to start editing early today otherwise its going to be another late night … not that I object to it that much, but if I do it too often people start calling me anti-social lol.
[/15.00]


[16.00]
Jumped on mumble with an old friend lost an hour chatting and catching up,  now finalised the details for the hakology private mumble message me for access. (@hakology)
Talking HAM, networking and IOT. Just about to start collating media for tonight.
[/16.00]


[16.58]
Success! Everything is running like clockwork, sometimes when I do videos I end up setting ridiculous time limits and today was a smooth operation. I’ve had times where I’ve planned to do something and about 90% of the way through realised it’s going to take way longer than I initially though or I was missing a critical piece of kit … well not today 🙂 Taking a little breather need to sort the garage before my friend arrives. BBL *having a brew and a quick reddit 1st though :P* PS. Don’t forget to add the hakology twitter account … http://twitter.com/hakology
[/16.58]


[22.32]
Back from a couple of hours climbing at the local climbing gym, had a cup of tea with an old buddy. Didn’t do anything too challenging because its the first time I’ve been for a few weeks after almost slicing my finger off but that’s another story. Back to work, kettle on, time to get editing, recording audio and sequencing stuff.
[/22.32]


[00.45] [05/10/2016]
Audio recorded, media collated, just catching up with a friend back off holiday then on with the late night editing session. LEEROY JENKINS!!!
[/00.45]


[1.40]
Coffee break editing is going well. Still nowhere near finished. Will report back later.
[/1.40]


[3.38]
Video done, I could have spent way more time working on polishing it up but the data is there, might do a follow up video on configuring it to work with the steam controller. Very tired starting research on SDR and some other TOP SECRET VIDEO IDEA STUFF 😛
[/3.38]



[4.27]
I’m none the wiser to what I’m doing tomorrow but I’m sure ill work it out, sleep time.
[/4.27]