Wednesday 3 August 2016

Shutdown of TP-Electronics

I no longer maintain this blog (for some time!)

Moved my base of operations to:

www.equalsequals.co.uk

Thank You

Tuesday 17 November 2015

Project: Raspberry Pi / Arduino Television Showcase


I was asked to showcase a poem with the following spec:

Seven TVs will be playing seven different videos and all must be queued simultaneously. This particular project is for a charity so there are obvious budgetary restrictions.

In the past, for multiple video feeds, the cheapest way would have been using DVD players, with obvious control problems.

Thanks to the raspberry pi, this can be achieved for £30 per output, and there are more control options than you can shake a stick at. We were able to achieve less than this thanks to there being a new generation of Pis available and eBay sellers moving them in bulk.

The first thing to do is burn the raspbian operating system to an SD card for each one of the raspberry pis.

I downloaded the image from raspberry pi foundation and used Win32DiskImager to burn the image to each card.

Now we had pi potential, we had to figure out how to power them.
I happened to have an old ATX power supply that I liberated from a PC tower that someone was very kindly throwing into a skip, and due to the low budget of this project I thought that was perfect.

I started by removing the top cover and fan from the power supply and connected all of the cables of the same colour together. I then mounted the fan on the top (and outside) of the ATX, leaving space for connections inside.

From previous experience, I knew that the red wires were for the 5V line and the green wire had to be low (connected to ground) to enable the maximum output of the ATX. but you can see from the chart below the other voltages:

Afterwards, it was a case of stripping back 7 micro USB cables, soldering them together (so they'd take to the connector blocks more easily), and connecting them to 5V and GND.





Always best to check just in case.

What I was then looking at was effectively a 7-way mobile phone charger.


Next thing was to load video files on to each raspberry pi.

I accomplished this by connecting each one to a network switch and a wifi router. Through the routers settings I was then able to bind the raspberry pi MAC address with a given IP address, and then labelled each Pi with that IP, for ease of troubleshooting just in case.
This one shows before I added the switch, not enough ports!!
I then used an sftp program called filezilla to transfer each file to the root folder of the corresponding Pi.

(
a quick and dirty how to:

 - SFTP uses SSH to transfer files, in filezilla quick connect bar plop in the IP address of the Pi, username and password and port 22, the SSH port open by default on raspbian.
- This then bring up a very familiar drag and drop style file tree, with your local files on the left and the Pi's on the right. Just drag and drop the files to the pi.
)


After this step was when i realised that the Pis needed to be mounted to make them more manageable.

So I took this board and (I don't advise this looking back on it), took some 30mm screws, and mounted each pi to it.

I had one very early pi that didn't have mounting holes through it so I fastened it down with some plastic cable tie fixings, hence the odd looking one.



I will be continuing with the rest of this project in another post, where I will show the easiest and cheapest way to control several pis at the same time. (HINT: it's not via network).



Monday 26 October 2015

ESP8266 AT Commands

Here are AT commands that you can pass to ESP8266 via Serial to make it do things.

credit: http://nurdspace.nl 


CommandsDescriptionTypeSet/ExecuteInquirytestParametersExamples
AT+RSTrestart the modulebasic----
AT+CWMODEwifi modewifiAT+CWMODE=<mode>AT+CWMODE?AT+CWMODE=?1= Sta, 2= AP, 3=both
AT+CWJAPjoin the APwifiAT+ CWJAP =<ssid>,< pwd >AT+ CWJAP?-ssid = ssid, pwd = wifi password
AT+CWLAPlist the APwifiAT+CWLAP
AT+CWQAPquit the APwifiAT+CWQAP-AT+CWQAP=?
AT+ CWSAPset the parameters of APwifiAT+ CWSAP= <ssid>,<pwd>,<chl>, <ecn>AT+ CWSAP?ssid, pwd, chl = channel, ecn = encryptionConnect to your router: :AT+CWJAP="YOURSSID","helloworld"; and check if connected: AT+CWJAP?
AT+ CIPSTATUSget the connection statusTCP/IPAT+ CIPSTATUS
AT+CIPSTARTset up TCP or UDP connectionTCP/IP1)single connection (+CIPMUX=0) AT+CIPSTART= <type>,<addr>,<port>; 2) multiple connection (+CIPMUX=1) AT+CIPSTART= <id><type>,<addr>, <port>-AT+CIPSTART=?id = 0-4, type = TCP/UDP, addr = IP address, port= portConnect to another TCP server, set multiple connection first: AT+CIPMUX=1; connect: AT+CIPSTART=4,"TCP","X1.X2.X3.X4",9999
AT+CIPSENDsend dataTCP/IP1)single connection(+CIPMUX=0) AT+CIPSEND=<length>; 2) multiple connection (+CIPMUX=1) AT+CIPSEND= <id>,<length>AT+CIPSEND=?send data: AT+CIPSEND=4,15 and then enter the data
AT+CIPCLOSEclose TCP or UDP connectionTCP/IPAT+CIPCLOSE=<id> or AT+CIPCLOSEAT+CIPCLOSE=?
AT+CIFSRGet IP addressTCP/IPAT+CIFSRAT+ CIFSR=?
AT+ CIPMUXset mutiple connectionTCP/IPAT+ CIPMUX=<mode>AT+ CIPMUX?0 for single connection 1 for mutiple connection
AT+ CIPSERVERset as serverTCP/IPAT+ CIPSERVER= <mode>[,<port> ]mode 0 to close server mode, mode 1 to open; port = portturn on as a TCP server: AT+CIPSERVER=1,8888, check the self server IP address: AT+CIFSR=?
+IPDreceived data

Friday 11 May 2012

How to Run Your Own Python Scripts on an Android Device

While I don't usually post my programming activities on this blog, I have been dedicating increasing amounts of time dedicated to it. Especially now that I have just acquired my first android phone (sayonara iPhone) I have been wanting to run my own scripts on it. Now since I don't have much (any) experience programming java, the native programming language for android, I decided to set about figuring out how to run scripts in a language that I do know, hence python for android. Android app development is possible with just your home computer with some free software and you are free to run it on your device without a jailbreak that might void your warranty (unlike another popular smart phone).

Firstly, I will show you how to set up your android device to run Python scripts using a google product called Scripting Language 4 Android (SL4A). This is fairly straightforward.
Firstly, you need to make sure that you allow your phone to install software from unknown sources (in settings). Then, in your android internet browser, navigate to code.google.com/p/android-scripting. Then click on the QR code (black and white box) and proceed with downloading and installing SL4A.
Next, you are going to want to go back to the page and on the left hand side under featured>downloads, you'll want to download and install PythonForAndroid_r4.apk (latest at time of writing). Once the download of this is complete DO NOT CLICK UNINSTALL, it's easy to do, that's why I'm warning you.

Where to click in the SL4A download site


OK, so now the phone is set up to run python scripts and if you now navigate to SL4A (comes up just like a freshly downloaded app should), as in the image you should be able to see all of the pre-loaded python scripts.

SL4A and Python for Android icons
important Python scripts
In the image I have highlighted two scripts in particular. The first is the Hello World app, very straightforward, it will just print "Hello World!" in your notifications bar. The second is more interesting, test.py will show you a run through of features available to you as an Android Python programmer. It is definitely worthwhile to run this app and study the code carefully.

It doesn't seem to want to let me take a screen capture of it, but when you click on one of the scripts to run it, there are five icons that appear and the functions of them are as follows (from right to left): Run python script in terminal, Run python script, Edit python script, Rename python script and, finally, Delete the script.

OK, that's all well and good for running Python apps on the device, but for development the inbuilt script editor probably isn't the best way of doing it (unless you enjoy coding on a tiny screen and you own a bluetooth keyboard and mouse). So, for editing and quickly testing your scripts you are going to want to set up the android SDK and start up an emulator. I am not going to get into setting up the android SDK on this tutorial as it's different between operating systems and I'll be here all day. I may do in the future but for now I will only say it's a case of downloading eclipse from www.eclipse.org and the android SDK from http://developer.android.com/sdk/index.html. However, if you don't know what you're doing just do a google search for "set up android SDK on (insert operating system here)". There are loads of tutorials on blogs and youtube and developer.android.com itself.

Now, once you have the Android SDK set up and eclipse is running, you're going to need to set up an android emulator and do what is described above for your handset on the emulator (and bear in mind that the emulators run much more slowly than your device should). To do this, open eclipse (once the SDK is set up) and click window(eclipse on mac)>AVD manager. Then click New... and you should be on the setup page for an Android Virtual Device. Name it whatever you like and under target choose whichever android OS version you desire. Set storage to whichever value you like also (over 9MiB) and click Create AVD. That's it! once that is finished click start while the AVD of your choosing is highlighted and you will have your very own android emulator running on your system.

Now that an Android Virtual Device is set up and running on your system, you are going to need to install SL4A and python (same as described above but in the emulator) and you are also going to have to know how to transfer python scripts for testing out your applications (this is where I cant help windows and mac users, but you can do a search on it, or upload the python script to a site or email and download it to the emulator). Now, when setting up the SDK you downloaded a directory where it lives, right? Inside this directory (android-sdk-linux on my machine) there is a folder called 'platform-tools' and the tool we are looking for is called 'adb'. This tool will allow us to push files to the android emulator, and here's how:

First, copy your python script to the android SDK directory.
Then use the command:

$ tools/adb push (your file).py /sdcard/sl4a/scripts

to push the file to your emulator.
Once this is complete, open SL4A and you should now see your Python script sitting there ready to be run. Congratulations, you are running your own python script on android! Nice.

One more thing, always be sure to send your scripts (whether on the emulator or your handset) to sdcard/sl4a/scripts. If you don't, you wont be able to run them from sl4a. Thank you, goodnight.







Wednesday 8 February 2012

Light to Music Synchronisation Prototype (Video)

I have successfully finished a prototype for an LED colour organ project (LED to music synchronisation).
The prototype is the circuit on a breadboard and a small LED array.
I am still fine-tuning the circuit, and obviously once I do I'll solder it to a perfboard to make it permanent.
However, right now I just wanted to show it off, especially the frequency dependency of the LEDs.
It is far from finished, the final product won't just have 4 LEDs flashing.
No microcontrollers were used in this project, though it probably would be a heck of a lot easier if I had used a microcontroller.
Video follows, cheers.

The Colour Organ (Video):