Raspberry Pi Counting in Binary
As a simple Christmas project at GroovyCart we thought we would have a play with a Raspberry Pi computer, we got various small projects working and we thought it would be worth posting some examples and samples of our code for anyone else that it might benefit.
This article is intended to help people that are developing their Raspberry Pi, however it may also inspire some of our shop owners to turn their hand to a bit of programming.
So the first project we will be looking at will be setting up 3 LEDs on a breadboard and connecting them to a Raspberry Pi that will programatically get them to turn on and off counting in binary. These are the GroovyCart Christmas lights.
Here are the numbers for anyone interested:
001 010 011 100 101 110 111
(0=light off, 1= light on)
Here is a video of the finished project here:
We used a breadboard to connect 3 LEDs to the Raspberry Pi via the GPIO ports, we will skip over that part because there are so many guides to doing that on the internet.
We found the easiest way to interface with the GPIO ports was using Python, once again there are loads of guides for setting up python on a Raspberry Pi and we don't want to go around repeating what others are already saying.
So a really quick overview of what we set up. The Raspberry Pi has 26 pins called GPIO pins that can be used to either send a signal out of the Pi or detect a voltage coming into the Pi. From the Pi we connected pin 6 to the Breadboard and used this as the ground for our LEDs. We then used pin 11, 13 and 15 (sidenote: the Pi refers to these as GPIO 17, 21 and 22 respectively) to send a voltage out to power the LEDs.
We also had to put a resistor before each LED and for us the hardest part of the project was finding out what resistors to use.
Now we get to the fun part.
In Python we used PRi.GPIO 0.4.1 to start activating the GPIO pins.
Once this is installed you can pull up a Python terminal window and enter:
import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(11,GPIO.OUT) GPIO.setup(13,GPIO.OUT) GPIO.setup(15,GPIO.OUT) L1 = 11 L2 = 13 L3 = 15 delay = 0.5 def changelights(led1,led2,led3): GPIO.output(L1, led1) GPIO.output(L2, led2) GPIO.output(L3, led3) print "LEDs = ",((led1)+(led2*2)+(led3*4)) time.sleep (delay) return while True : changelights(False, False, False) changelights(True, False, False) changelights(False, True, False) changelights(True, True, False) changelights(False, False, True) changelights(True, False, True) changelights(False, True, True) changelights(True, True, True) time.sleep (delay)
This will output onto the screen:
LEDs = 0 LEDs = 1 LEDs = 2 LEDs = 3 LEDs = 4 LEDs = 5 LEDs = 6 LEDs = 7 LEDs = 0 LEDs = 1 ....
So lets break it down:
import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(11,GPIO.OUT) GPIO.setup(13,GPIO.OUT) GPIO.setup(15,GPIO.OUT)
This just sets up the delay and also the GPIO software
L1 = 11 L2 = 13 L3 = 15 delay = 0.5
This initialises the variables, the first 3 lines select the pins we are going to use and the last one is the speed the lights change at.
def changelights(led1,led2,led3): GPIO.output(L1, led1) GPIO.output(L2, led2) GPIO.output(L3, led3) print "LEDs = ",((led1)+(led2*2)+(led3*4)) time.sleep (delay) return
This is just a function used to change the lights and then display a count in the terminal. Functions in Python are done by indentation.
while True : changelights(False, False, False) changelights(True, False, False) changelights(False, True, False) changelights(True, True, False) changelights(False, False, True) changelights(True, False, True) changelights(False, True, True) changelights(True, True, True) time.sleep (delay)
This last bit of code just loops around and also selects what lights should be on.
Contactless Marketing with NFC
At GroovyCart we have been playing with NFC (Near Field Communication) Chips, these are the chips that can be found in Oyster Cards, Barclay PayTags and in Google Wallet.
NFC chips are very small memory cards that are thin enough to be put into stickers. You can then use mobile phones and other devices to access the data on them wirelessly. There is no battery on the chip so this allows them to be low cost and light weight, they are powered by radio waves from the mobile phone and the data can then be read and edited.
There are different chips of varying signal strength and storage space. The newest of which is NTAG203 which is the smallest and has the best signal strength and storage space, however there are Ultralight C and Standard 1k NFC chips as well of different shapes and sizes.
We have put together a video showing our new business card with an NFC Chip on the back that when put near a HTC One X it boots up a browser and automatically goes to our website.
|Chip Type||Size||Pages (number of storage areas)|
|NTAG 203||168 Bytes||42|
With the new update to android phones (4.1 Jelly Bean) there is a new icon at the top saying NFC with a wave above it. The NFC Chip can be programmed to do many things like loading a browser and adding contact information into the address book without making any changes to the phone, however with an extra app the phone can be told to change wifi information or send E-mails as well as many other things, this makes NFC chips very powerful.
Product QR Codes
Ok, so what's a QR Code and how can it help you sell more products on your GroovyCart shop?
QR Codes are a handy way of giving smart phone users easy, direct access to a web-site, without the need for the user to manually enter a URL web-address into the browser.
The QR Code is a checkerboard square made up of black and white squares, generally with large squares in three of the corners to help the scanner locate the QR Code.
They can be any colour, although they are generally black, and can be any size.
You may have seen them appearing in magazines and shop windows.
On GroovyCart, we have taken this one step further. A shop-owner can print-off labels which contain a picture of a product with a QR Code that contains the URL web-address of that product. In addition, a shop-owner can even print-off a label with a QR Code that just has the URL of the shop home page.
The labels are designed to fit Avery L7165 sticky labels 2x4, however you don't have to use sticky labels.
A customer can simply scan the QR Code using their smart phone, and the product will be displayed on their smart phone browser. They don't have to type the URL web-address, it is done automatically for them. They can even purchase the product using their smart phone. Incidentally, GroovyCart will detect that the device is a smart phone and will display the product so it fits the smaller screen, and is easy to read.
This is another great way to market your products. Here are some ideas on what you do with the printed labels...
- 1) stick them in a window, so customers can purchase when you're not in,
- 2) stick them on parcels,
- 3) use them on business cards,
- 4) make a printed book of your products,
- 5) stick them on post-cards,
- 6) fill a whole space with all your products.
You can find the QR Codes labels functionality under the Marketing button on your GroovyCart Admin-Panel.
If the smart phone doesn't have a QR Code scanner app by default, there are many QR Code scan apps available, including free ones.
A Peek of Things to Come.
Click to see full size image.
A new Edit Widgets Page
We have updated the edit widgets page with an aim to make it quicker to update and more intuitive to learn.
We have also added 13 widgets and updated some others. Most of the new widgets have been developed to either help send your customers to social sites you use to help obtain their trust, or to be used as a tool to help inform them and keep customers up to date with new products and promotions.
New widgets include:
- Twitter Feed
- Facebook badges
- Blogger Link
- LiveJournal Link
- Tumblr Link
All this will be coming soon in the next deployment.
Development Methodologies - Rapidly Building Useful Websites.
We have all heard of horror stories of big software developments which are late, overrun budgets or simply don't delivery functionality. Generally, this is down to a long development cycle where requirements are gathered up front way before the software is built, resulting in the final system being "this isn't what I asked for".
So I thought I would take a bit of time to tell you about how we work at GroovyCart.
To avoid these catastrophes, the GroovyCart team have adopted an Agile approach to software development. Broadly, the team adhere to the following:
- Developments are split into fixed iterations of, generally, 2 weeks.
- Every iteration has deliverables.
- The requirements scope fits an iteration.
- Each iteration goes through the full life-cycle of development, test and deploy.
- There is a review at the end of the every iteration meaning the client can monitor development.
- The scope for the next iteration is decided at the end of the previous iteration.
Ok, so what happens in practice? The very first 2 week iteration is about identifying the key deliverables and roughly allocating these to iterations. For the first release of GroovyCart we planned for 6 iterations. At the start of each iteration we would collectively decide what deliverables will be developed. Generally, these deliverables will form the test plan/specification for that iteration. Where a deliverable is more than 2 weeks work then it is split up into smaller deliverables. At the end of the iteration, the development is tested and "driven to live". So at the end of the 2 week iteration there is a working, demonstrable system, which the client can view. We then decided what is going into the next iteration. Ok, so what happens when things go wrong. If a piece of software is taking longer to develop then work on that individual deliverable it is split across iterations, i.e. the iteration is still deployed on the due date. If the client doesn't like the look of a deliverable then the subsequent iteration will address this.
What does this mean for GroovyCart?
Our Agile approach ensures we are develop features on GroovyCart quickly, and be responsive to our shop-owners requirements for new functionality.