Wednesday, February 21, 2018

PiGPIOPin - when you want to use pin numbers and not BCM on the Raspberry Pi in Python

A while back I was doing some bare Arduino compatible boards using the ATMega328 chip. From this I saw that Arduino did not map the pins on the IC to the same numbers on the Arduino.  They used a simple order on the Arduino board and the Arduino ID so it was easy to find the right pin for wiring and also for your code.

Only problem is when you use the chip with the bootloader the mappings are different to the pin number so you need a lookup tool to know when you want to use Arduino Pin 13 that it's ATMega Pin 19.
After a while this became a bit annoying so I put together an .h file with a bunch of constants that got around this.

http://www.winkleink.com/2014/01/arduinopinsh-converts-atmega328-pins.html

On the Raspberry Pi there is a similar situation.  The default numbering mechanism used is the BCM numbering which is great if you're operating at chip level, but at a board level it means things like:

BCM GPIO 5 is board pin 29

I still have to count pins to get to board pin 29, so having to also know it's then GPIO 5 in my code can sometimes be a bit annoying.

The original RPi.GPIO library allows you to choose BCM or Board numbers

 import RPi.GPIO as GPIO  

GPIO.setmode("GPIO.BCM")
or
GPIO.mode("GPIO.BOARD")

Giving the user the choice.

With the fantastic GPIOZero BCM numbering is enforced and there is no option to use board numbering.
GPIOZero is a great library and makes controlling motors, working with MCP3008 (analog input) and distance sensors a lot easier.

For those who want to use board pin numbers and want to take advantage of GPIOZero the use of the BCM numbering can be annoying.

To make it easier I decided to do a similar lookup table like I did for the Arduino.
Mapping Pin number variables to BCM numbers.
The code and an example is on GitHub.

It's straight forward to use.

Have PiGPIOPin.py in the same folder as your code or in the python path.

Put the following line at the top

from PiGPIOPin import *

Then instead of using something like

red = LED(17) # 17 is the BCM number that is at board pin 11

use

red = LED(PIN11) 

Each BCM number is mapped a PIN* variable.

The rest of the code then works as normal.

Using this gives the option back to use board pin numbers and not BCM numbers.





Thursday, February 8, 2018

More cheap stuff from eBay - Gaming Player Handheld Video Tetris Game Console Kids Children Boy Portable Toy



I'm drawn to the underside of eBay. The placed where strange bits of electronics are sold.  This interest comes from making things and needs odd bits of electronics to realise my (awful) creations.

On one of my regular trawls of ebay I found this.

Gaming Player Handheld Video Tetris Game Console Kids Children Boy Portable Toy


Looked interesting.  OK the display is obviously mono-colour LED and not back lit but for £1.39 I thought it was worth a punt.

From the Listing the dimension are: Product size: 14*8*2cm
Bigger than the Sony PSP Go 12.8*6.9*1.64cm
If Sony can squeeze a 4.3" widescreen display in the PSP Go then this could be a very useful case to work from. A nice sized case with 10 buttons.

For reference a Raspberry Pi Zero is 6.5cm x 3 cm.  An easy fit and with dimensions greater than the PSP Go one of the many 3.2" LCD displays I see running from a Pi should fit nicely.

£1.39 for a case with 10 buttons that should easily take a Raspberry Pi Zero and 3.2 " screen with space for other bits is a bargain.

I see a plan coming together so I ordered one two weeks ago and it arrived today.

The packaging is the same as the listing which is always a good start.



Opened the box and inside was the actual console. OK a bit rough and the sticker isn't straight.  Not a problem as I plan to remove all that anyway.




But there was something else not right.  I checked the listing again and confirmed the dimension Product size: 14*8*2cm

The dimensions on the actual one I received seem a bit off.  Annoyingly I don't have a ruler with me at the moment so I'm using AAA (not AA) as the standard measure.

An AAA battery according to Wikipedia is 4.45cm long.
From the picture below it looks like this may not be 8cm wide or 14 cm in length.



It is more like 9cm in length so a Raspberry Pi Zero may still fit inside and 5cm in width.
There goes the plans for a 3.2" LCD display. Maybe one of the  0.96" OLED displays might fit.


I almost forgot.  What about the 999 games.
It does have Tetris, a variety of Breakout games, a Tank combat game and a Driving game.

The driving game is especially bad as there are only 2 lanes and you just move from left to right as the cars come down the screen.




In summary how does it compare to the listing title.

Gaming Player Handheld Video Tetris Game Console Kids Children Boy Portable Toy
It is a game playing handheld video Tetris Game Console.
No kids, children or boys included, but it definitely is portable and a toy.

As an added bonus you also get the amazing driving game, breakout and tank combat games, so in a way it over delivers on the gaming promise.  I didn't count whether there are 9999 but I suspect we all know the answer to that.

But, if your reason for getting it is to have a 14cm x 8cm x 2cm case with an opening to put a 3.2" display and a Raspberry Pi Zero you will be very disappointed as it's most definitely a lot smaller than the listing.

It is held together with screws so maybe a teardown is needed to see what's inside and if there is anything I can salvage from it.



UPDATE:
I think I may have found an actual correct listing for the one I purchased
http://www.ebay.co.uk/itm/272730431909
Listing states the dimensions are: 10 x 4.5 x 2.4cm

Then there's also this listing for £1.79
https://www.ebay.co.uk/itm/222452404318
With the dimension listed as: 15.5*6.5*2.5cm

If the larger one really is those dimensions then a project may be on to use it as a shell for something more fun.