Subscribe to Blog via Email
Follow me on TwitterMy Tweets
After returning from KSCOPE two weeks ago, I was again approached to be a judge this year on the Geekathon 2017.
I was thrilled when the option was left open to me to compete this year. instead of be a judge. As much as I love to offer my insight and expertise in a judging capacity, I really do love a great maker opportunity, which I haven’t had much time to allocate to with all the work I’m doing at Delphix.
Needless to say, I’m looking forward to this year’s competition, so look out maker’s, there’s a new…err, old gun….old set of Mickey ears in town! (For those of you who aren’t getting that, next year’s KSCOPE 2018 conference is in Orlando, Fl…. :))
I’ve been part of the maker’s space for a number of years, finding it one of the most diverse and supportive groups in the nation. I’ve presented at local events and been advertised in the NY Times to represent makers for the Barnes and Noble Book store events.
I’ve officially built out my proposal and submitted it as a team of one, but if you’re new to the makers space, unsure of what to do with a beacon or would just like to have a team to collaborate with, that’s an option! Just find your maker-mates, come up with an awesome idea and if you need a beacon, just ask- the ODTUGr’s will be glad to send you one so you can compete! Just go to the ODTUG Geekathon site and submit a team and an idea!
With me traveling to Redwood City next week to visit HQ and then Oracle Open World the week after, I’m busy during many of my off hours preparing a new Raspberry Pi STEAM setup for a maker’s faire the beginning of October.
I’d heard that many were having challenges with installing different HATs on their new RPI 3, especially older ones like the Pibrella.
This is still one of my favorite accessories for my RPI due to the button, speaker and three LEDs, but also since I can hot swap jump wires without risk of shorting out the unit like when you’re using the direct GPIO on the RPI.
I have a great new setup for travel for my Raspberry Pi that has the newest 7in touchscreen and protective case, which opens on the back. Could I install my Pibrella with the constricted opening and the GPIO wires still powering the enhanced touchscreen card?
The Pibrella requires 26 of the pins to function and installation asks you to place the unit to the 1st pin. It has a mini USB connector for power, but can run off of the GPIO. The challenge is that the new 7inch touchscreen ALSO is powered by the RPI GPIO, connecting to pin 2, (5V) and 6, (Ground.)
When a competing configuration is found for GPIO, its important to inspect the GPIO map and see what is available:
Now using the above map, you’ll notice that pins 1, 2 and 3 are all power. The Pibrella ONLY needs one 5V power source, which means that installing it from the first pin may be best practice, but it’s not required. OK, so that means we can still use Pin 2 for the touchscreen. Now, if we move down the Pibrella one, that leaves 6 rows of pins free at the other end. The 6 pin, which is the second necessary pin for the touch screen to ground it, can be shifted to the 39 pin, which is another ground pin!
I then moved the GPIO pins for the touchscreen and installed the Pibrella to the RPI 3. It was a tight fit, but it did install:
The next thing was to test it all. Each of the GPIO connected match to the GPIO attached. These will have to all be tested to see if there are any mismatches between the board and the RPI. The Pibrella library that is installed is just functions that have been written to tell what pins correspond to what commands.
So I run a small test script:
import pibrella import time pibrella.light.red.on() time.sleep(2) pibrella.alarm.on() pibrella.light.red.off()
This script is to turn on the red light for 2 seconds, ring an alarm and then shut off the red light.
What happened? The amber light lit on and then off. No alarm- yep, may have my monitor working and power to the pibrella, but as suspected, the GPIO orientation is off for each of the LEDs, alarm and I expect, the GPIO connections on the board.
Now I could give up my pibrella….or the touchscreen, but what if I’m just plain stubborn and want both?
So the files I need to work with are in the distribution packages for Pibrella. I had to go to /usr/local/lib/python2.7
Now you may be wondering why this was in the Python 2.7 instead of the 3.4 distribution… RPI 3 still has the 2.7 python set as default. If you don’t change this, then this is where you go. I prefer RPI 3 and write my code per Python 3 standards, but I’m not surprised the Pibrella library installed here.
Inside this directory, under the dist-packages is the Pibrella directory and it’s just a matter of .py, (python) files. There is one called pins.py that I had to update to reflect the changes I made to my match my installation. Now, we can fun the red light script and it actually lights up the correct LED.
It appears the alarm and button are set up in a different set of code, so now I need to just locate the other python scripts for the alarm and such and get that corrected.
That doesn’t mean I can’t get motors and other devices working from the new setup….
The following issues in this post are common challenges experienced by Raspberry Pi, (RPI) owners and I’m consistently frustrated with the ridiculous answers out on the internet for them! No fear, trusty Raspains! I’m here to offer you the correct and [pretty easy] answers that will actually fix the problems and won’t lead you to searching for hours on the internet.
We techies know that no matter what, going back to the configuration at the OS, (operating system) level is just the best way to fix problems. Raspberry Pi issues are no different, so read on…
If you haven’t figured out by now, your RPI, although globally distributed, was built in the UK, which means that the keyboard is set to “gb” for Great Britain. With that comes the pound sign when the shift is depressed and you then press the number 3, among other key reassignments. Yes, there is a configuration option in the user interface and yes, it will fail to correct the issue, even after you’ve rebooted.
There is a simple configuration file update, so let’s just fix this the proper way. Using Vi, Vim, Nano or another command line editor, edit the following file, (I’m a DBA, so Vi is my trusty editor choice):
sudo vi /etc/default/keyboard
# KEYBOARD CONFIGURATION FILE # Consult the keyboard(5) manual page. XKBMODEL="pc105" XKBLAYOUT="gb" XKBVARIANT="" XKBOPTIONS="" BACKSPACE="guess"
Update the XKBLAYOUT to “us” from “gb”, (or to the keyboard layout language you need it set to.)
Save the changes and cycle the RPI. There, all fixed.
The 7 and 10 inch touchscreen displays allow the user to have a more portable RPI, (non-dependent upon an HDMI monitor or TV) or mouse. I also prefer it, as the low-powered option allows me the opportunity to power my RPI, monitor, et. all on an 20800MAH mobile charger battery, walking away from a standard power source completely.
The challenge is that when you position the RPI into the case that makes this all so easy to work with, the display is upside down. No, there’s nothing wrong with your screen or your installation, the problem is the configuration for the RPI. This can be easily fixed, again, with a simple update to a configuration file and power cycle of the RPI.
This time, edit the following:
sudo vi /boot/config.txt
add the following line to the bottom of the file:
The file should now look something similar to this:
# Enable audio (loads snd_bcm2835) dtparam=audio=on # Correct display orientation lcd_rotate=2
Save the changes and cycle the RPI. Again, all fixed…. 🙂
If you have challenges with this, check out my blog post that goes into causes and fixes here.
Hopefully people won’t be looking all over the internet for these fixes and just find this post instead…. As I think of other fixes, I’ll continue to update this blog post, so check back!
So there are some cool features that are built into the GPIOZero library/module. One of the challenges I think many of us that have a lot of projects that we want to work on, is that we end up having to translate it to the version of RPI that we just happen to be working on or have available. This can be frustrating when the code is available without us having to rewrite it all in the libraries available for the hardware we just happen to plug-in.
So GPIO the old way with photocells is a bit involved:
GPIO.setmode(GPIO.BCM) def RCtime (RCpin): reading = 0 GPIO.setup(RCpin, GPIO.OUT) GPIO.output(RCpin, GPIO.LOW) time.sleep(0.1) GPIO.setup(RCpin, GPIO.IN) while (GPIO.input(RCpin) == GPIO.LOW): reading += 1 return reading while True: print RCtime(18) # Read RC timing using pin #18 <and on and on..and we haven't even got to the buzzer, etc....>
If we use the GPIOZero library, it’s much simpler due to a module written for physical computing with photocells:
from gpiozero import LightSensor, Buzzer from time import sleep ldr = LightSensor(18) buzzer = Buzzer(4) while True: sleep(0.1) if ldr.value < 0.5: buzzer.on() sleep(30) else: buzzer.off()
LightSensor was what I wanted and it was already available in the GPIOZero library.
Needless to say, this happened to me as I was working on a new project. I was at the Starbucks and pulled out my Raspberry Pi, B+ Release 2, that has the touchscreen built in, plugged it in and went to town. With this configuration, I only require one plug, (the monitor works off a battery) and it’s very portable when I’m out and about.
So what did I do when I saw the module to call was GPIOZero and I was on the Raspberry Pi 2? I installed the GPIOZero library, of course!
sudo apt-get install python3-gpiozero
I keep the images updated with the latest, so it was a no-brainer to add this to it.
If you don’t have what you want for the model you are working on, why not just try to install what you need?
Easy-peasy, forty pin GPIO library done. So there, Raspberry Pi Versions!
This morning, after someone added SQL Developer to a Raspberry Pi 3, Jeff Smith pinged me and the question was posed, as it often is, can you run Oracle database server on a Raspberry Pi, (RPI)?
The answer is no, you can’t, as there are no binaries for the ARM processor platform that you can compile, so its nothing to do with power, (although it is low powered for a very good reason…) but really due to the processor type. Hopefully that’ll stop those of you building out massive RPI clusters in hopes of creating their own home servers with these inexpensive computers.
With this said, you can run a database, so to show how easy this is, I’ll show you how to install and work with an installation of SQLite on a Raspberry Pi Zero, the version that’s less than 1/2 the size of a credit card.
Other people have a beer and take the evening off. Me? I have a beer and start installing stuff on single board computers… 🙂
Installation is easy. Ensure you have the latest update, so if you haven’t run your update in awhile, run that first from the command line. Remember you must have root or sudo privileges to perform these tasks:
$sudo apt-get update
Once complete and you know you’re up to date, then simply get and install SQLite:
$sudo apt-get install sqlite3
Let’s create a database:
This creates the database using the mydb.db file as the logical container for it.
Note: If you need help at any time, you can type in .help or .show from the sqlite prompt and it will display information similar to man pages in linux. It’s very helpful and user friendly.
If you’re out there comparing features, about to complain about all the ways that SQLite is NOT Oracle, well, you can stop right here. On the support page for SQLite is the quote:
Small. Fast. Reliable. Choose Any Three.
SQLite isn’t trying to be Oracle, but if you need a database and you’d like to put one on a RPI, this is the one to use that is small, fast and reliable.
Of course there are some syntax differences and SQLite has most standard SQL syntax at it’s disposal. Remembering to type BEGIN for the implicit transactions and to COMMIT after each is commonly the biggest challenge. This includes for data dictionary objects, (aka ddl).
As this isn’t a full RDBMS client/server database, there aren’t any roles or privileges that reside outside of the OS level privileges to the database file. This database works very well in the support of RPI projects and this is the goal of what I’m hoping to demonstrate here.
So let’s start by just creating a table and adding a few rows.
begin; create table tbl1(col1_id text, date_c1 date, time_c1 time, range_1 numeric); commit;
Now you can insert rows into your new table:
begin: insert into tbl1 values('user1', date('now'), time('now'), 12); insert into tbl1 values('user2', date('now'), time('now'), 7); insert into tbl1 values('user3', date('now'), time('now'), 20); commit;
You can then select from your new table and the row(s) will be returned, separated by the pipe symbol:
select * from tbl1 where col1_id='user2'; user2|2016-03-22|00:12:237
So there you have it. Database software installed- check. Database created- check. Object created and rows added- check. Table queried- check. All done in less than five minutes.
If you’d like to learn more, you can check out SQLite’s home page.
Although the Raspberry Pi 3 is now available, many people are still interested in it’s cheaper, smaller version, the Raspberry Pi Zero. This version isn’t just smaller, it also requires a Wi-Fi dongle for internet access, (one of the new, great features on the 3 Model!) and one of my main reasons for not recommending it to newbies to the Raspberry Pi, (RPI) world, is that it doesn’t come with the GPIO pins pre-soldered.
GPIO, which stands for General Purpose Input and Output is an excellent feature on this single board computer, allowing an RPI to connect easily with sensors, motors and other external components. The original RPI came with a 26 pin GPIO setup, but since the Module B, it’s been a standard 40 pin GPIO that offers a myriad of project and hardware possibilities.
Now those that are seasoned RPI geeks will simply say to wrap wires around the appropriate GPIO connector or with jumper wires, just stick the connector through the hole-
Those that introduce RPI to those new to single board computers know that the quickest way to suffer a short out to one is by performing breadboard and other experiments that utilize the GPIO and we see the wrapping of wires and leaving more chance for wires for power, grounding and control to touch a penchant for human error. These errors leave us asking students to be prepared with a backup image of the software on hand to address the most common victim of a shorted out unit.
Now I could go into the dangers of GPIO, ampage current with a recommendation that all newbies start with an Ardruino or discuss the importance of transistors, but eliminating some of the risk by having the GPIO pin connectors makes sense.
Ardruinos are better at GPIO ampage handling, but they shouldn’t be confused with a single board computer and are limited in their application. The RPI and Arduino are both capable of sinking 50 ma through their GPIO pins, the difference being where you to acually sink 50ma, the RPI may very well be damaged, but the arduino will survive and doesn’t have an Operating System and software that may be seriously impacted.
Due to this, for those that may be intermediates, I recommend if you’re going to get the Raspberry Pi Zero, consider soldering the GPIO pins for it. It’s not difficult and there are a lot of videos that can teach you how to solder effectively.
A 60 watt 110V soldering gun with a couple of different soldering tips is all you need to do the work with just about any RPI project. Purchase the right kind of solder for the project you’re taking on. Note I have a picture of the solder I’m using below. Pins can be purchased from Radio Shack, MicroCenter and other “geek stores” or you can steal them from kits that can be purchased online, like this cobbler kit. The pins can be “broken” into the correct count to fit in the holes to be soldered and you’ll be soldering from the back side of the unit.
If the unit is in a case, please remove the case and ensure you remove any cables, micro SDCards, etc. that could get in the way or be in danger of harm by the soldering gun before you begin.
Set up your work area and I keep a piece of thick cardboard around to clean off any remnants of solder from my solder gun to keep it clean as I work. Add the correct number of pins and if you don’t have a single set of 40 pin addition you can add, work with one line at a time.
Once the first line of pins are added, turn the unit over and brace it so that the pins are straight. You don’t want them “leaning”, otherwise the pins could be soldered crooked and you could have challenges attaching units like a PiHat or other components that have configured GPIO attachments. I used the corner of my keyboard, as it was the right height and balanced it out nicely while I did the work. Make sure to use the right solder,- you can see what I used in the picture below:
Solder across the first line, taking care not to touch the actual Pi Zero with the soldering iron and once done with the first line, add the second line and solder it into place in the same way as you did the first:
Once finished, let it cool and check the connections. Are the pins tight and are they straight. If there is some angle to the pins, you can use the soldering iron to *carefully* loosen the solder and straighten them out some, but it’s better to be cautious and check it as you go to begin with.
Once it’s cooled and you’re satisfied with the pin placement, plug back in the Micro SDCard and if you had a case, put the RPI zero back into it. That’s all there is to it! You’re ready to create all kinds of fun projects with your RPI Zero and not worry so much about those pesky GPIO wires being exposed! Oh, yeah, still make a backup of your image using Win32 Image Writer….PLEASE!! 🙂
I’d had some difficulty with WiFi consistently staying connected on each of my Raspberry Pi units. I’d had a little time to look into it, but no research had offered an answer and the only fixes I’d come up with was a shell script I wrote to force a restart of the NIC, which helped some, but no improvement when I added an antenna, (I considered all the wires, sensors, etc. might be interfering with the signal.)
Finally this weekend, started to dig around and noted that although in the user interface, it showed both connections to my home WiFi and my Smartphone as enabled, the /etc/wpa-supplicant/wpa_supplicant.conf showed the following for each entry:
I couldn’t find any support documentation that backed up the theory that there was a mismatch in what the GUI stated vs. the configuration file that is the backbone of the settings, but with all the other data involved, it made sense that this should be set to either:
So, I took a deep breath and updated one WiFi connection entry in the file with “disabled=0”, saved and rebooted.
Sure enough, my connection to my home WiFi stayed connected and consistent to the internet. No more disconnects and no more challenges with connectivity.
Another change I made afterwards, which is backed up with support from multiple resources is editing the /etc/network/interfaces configuration file. Scan the file and look for an entry that says:
If you don’t see this entry, add a line to the top of the file, (you should see at least one other line starting with “auto” so add a line under that one if there is), save and reboot. This will update your RPI to start the WiFi NIC automatically, which will then in turn, connect to your WiFi network.
I’ve made this change to four of my five RPI, (the PiZero Jessie load doesn’t experience this issue and was what triggered that it was a software issue with Wheezy and not a hardware problem….)
This Saturday I’ll be part of a nationwide event being put on by the Raspberry Pi Organization and Barnes and Noble book stores. Makers Faire’s have been gaining international attention as the place to see really cool tech and inventions “in the wild” by everyday people making a difference.
I’ll be presenting at my local Westminster, CO store and am really looking forward to the event. I was approached by Matt Richardson from the Raspberry Pi organization to participate and I was really honored to be picked to be part of this. The event was even advertised in the NY Times, so pretty cool stuff!
I’ll be talking about why we’ve chosen Raspberry Pi’s to introduce technical education to kids and adults for RMOUG’s Raspberry Pi and STEAM special interest group, the coaching volunteer work I’ve been lucky to be part of with Oracle Education Foundation and my recent partnerships with Devoxx4Kids, which is just a great organization over all for introducing kids to technology.
Now lets get into the Raspberry Pi projects I’ll be demonstrating at the event. Physical computing is very interactive, which means that its not just about the code, but really helps kids understand how much you can control with code. The interaction keeps them engaged and with a few projects, they really start to embrace it.
I have two Raspberry Pi’s that I’ll be demoing- one has three projects connected via GPIO, (General Purpose Input/Output) with jumper wires. Two of the projects demonstrate how easy it is to purchase inexpensive models from a toy store and to hack them so that they can be controlled through code. The third project is just a motor, set up inside some Legos with a magnet and a plastic alien that can be positioned and spin in a dancing motion.
The take away from this project is to understand that the same code and a motor can do three very different things-
Here’s the actual code:
import pibrella from subprocess import Popen import time proc = Popen(['mplayer', '-slave', '-playlist', 'http://ramfm.org/ram.pls']) #stream music as subprocess def dance_e(): pibrella.output.e.on() time.sleep(10) #run for 10 secs to match music pibrella.output.e.off() def plane_h(): pibrella.output.h.on() time.sleep(5) #plane runs best at 5 seconds pibrella.output.h.off() def robot_f(): pibrella.output.f.on() time.sleep(3) #robot walking for 3 seconds is good pibrella.output.f.off() plane_h() robot_f() dance_e() #run motor alien last, give music time to buffer time.sleep(10) proc.terminate() #kill subprocess and exit
The code is simple and clean, doing what needs to be performed:
Start some music and while that is buffering and running in the background, launch the airplane, run the robot and then make the alien dance, which will start just after the music starts, too.
This is a project that I built out of an existing project I found online and then did some enhancements for Oracle Open World. I found myself at the conference without a co-presenter who had to go in for emergency surgery, so I wanted to do something with a Raspberry Pi and unfortunately, was out of time and our first idea was hardware challenged due to time constraints. I bought the bear in the conference retail center and began to work on him, introducing a Raspberry Pi to his innards and a camera in place of one of his eyes.
I set up app authorization to tweet via app.twitter.com and then built out the code from there with the additions I wanted for hashtags. I’ve now updated the tweets and hashtags to reflect the upcoming Maker Faire event, but here is the way the code works.
You click the button in his paw, the camera takes a picture, the code pulls from an array of tweets and hashtags, then it pushes it all and posts to Twitter-
The script calls an authorization file that grants it privileges to tweet as the RPI Oracle Bear user on Twitter. I installed the Twython module to use the code already built into the Raspberry Pi and configured my phone’s hotspot to ensure wifi access. I prefer my phone as it shows when the RPI is connected, verifying that I have wifi access, as there isn’t a monitor to display this information when the bear is active, (same with mouse, keyboard, etc. The code is running in the rc.local in the OS background, so no execution is necessary. It’s always on.)
from twython import Twython from picamera import PiCamera from time import sleep from datetime import datetime import RPi.GPIO as GPIO import random from auth import ( #authorization info for Twitter consumer_key, consumer_secret, access_token, access_token_secret ) GPIO.setmode(GPIO.BCM) GPIO.setup(14, GPIO.IN, GPIO.PUD_UP) twitter = Twython( #push auth codes to Twython consumer_key, consumer_secret, access_token, access_token_secret ) messages = [ #Tweets "Did you know over 7 million Rasperry Pi's have sold since 2012? ", "Nice to see you here! ", "You should follow @RpiOraclebear! ", "Do You Raspberry Pi? ", "Are you powered by a Raspberry Pi, too? ", "The Maker Faire at @BNBuzz ROCKS! ", "You can learn more about RPI at https://www.raspberrypi.org/magpi/! ", "A Raspberry Pi is only $35, you should get one! :) ", ] handles = [ #This is where you add hashtags to use "#RaspberryPi", "#BNMakerFaire", ] def main(): message = random.choice(messages) handle = random.choice(handles) with PiCamera() as camera: while True: GPIO.wait_for_edge(14, GPIO.FALLING) timestamp = datetime.now().isoformat() photo_path = '/home/pi/tweeting-rpibear/photos/%s.jpg' % timestamp sleep(3) camera.capture(photo_path) with open(photo_path, 'rb') as photo: twitter.update_status_with_media(status=[message handle], media=photo) #tweet will be a combo of one tweet and hashtag from list if __name__ == '__main__': main() camera.close()
This code is again very simple and clean. It’s not about making anything too complicated, just do the job that you want done. I’m considering moving the hashtags and tweet messages out to a separate files so if someone wanted to share the bear, (send it to conferences, people have asked…) that they could be given simple instructions to update the files and not the code, which would lessen mistakes.
I’ve added some velcro, secured the camera better into the eye socket with needle and thread, put all the batting in plastic bags to keep it out of the electronics and added a better button that “clicks” to know when the trigger has been engaged for the code.
Noel Portugal had a battery that worked really well with the RPI, so I’m going to hunt that down today, as I prefer the bear to be cordless, even for power. It just makes him all the more cooler to know he has a computer in him and like Pinocchio, no strings attached… 🙂
So I need to finish up my slides for this event, but I wanted to get the code out there and let folks know just what this event and the projects were all about. Don’t miss out, as I said, this is a nationwide event for Barnes and Noble, so look up your local store and be part of it!
There is an incredible power with the simple act of doing. People have a tendency to complain about the world, but there are only a few that refuse to simply accept it as it is and reach out to change it.
This video with the Red Pill Analytics guys, Stewart and Kevin, was a great opportunity to talk about something that is very important to folks like Jeremy Harms, (@EmeraldCube) and I. Jeremy is very active in the Atlanta area with his Code Crew events, introducing technology to locations that may not have the resources to offer this type of opportunity to the community. I also wanted to introduce it to my own community a while back and started working with my own resources at RMOUG as a Special Interest Group, (SIG), partnering up with Devoxx4Kids and Raspberypi.org. It’s incredibly rewarding as a teacher/coach/volunteer and really offers kids something they may not be able to get anywhere else.
I finished a great class this last Saturday, partnered up with Tuliva and Devoxx4kids. We had a really great time and productive, too! The kids learned about programming, development jobs and then I had them code two games, first a dice game and then Pass the Pigs, all in Python. Of the 20+ kids, over 85% finished their games and were able to play the games themselves or with one of the other attendees!
They just did a really great job and I was really thrilled with how the class did! Tuliva offered us a great venue to hold the class and their guys did a wonderful job ensuring everyone was up and running, (after we found out the Raspberry Pi’s didn’t like the VGA to HDMI converters for the monitors!)
I have no doubt that giving back and helping to focus the future of technology is what inspired Jeremy Harms of Vine City Code Crew. Schools don’t have the resources and it’s up to us to give back and build up technology for young people in the world.
Forty-one out of fifty states in the US still don’t require technical courses to graduate from high school and of those that do, a large majority of those classes are based on Office Technology vs. logical thinking or high technology, such as basic programming classes. One of the motivators for me was when I went to my children’s new high school and found out their pride in their multiple computer labs, all loaded with Windows 2000, how they would teach Microsoft Office programs and how to format a USB drive. This is not technology and when I asked about programming classes, I was told they did have them in the district, but kids needed to go offsite and attend the vocational school, called Bowman. This is both frustrating and depressing when we think that the only ones going into Tech out of high school are those that can’t make it in traditional high school.
So how can you get involved? There are a number of initiatives local and national you can reach out to.
So, reach out and be the change you want to see in the world. If we don’t do it, who will?
So in honor of coaching a Python introduction class with Devoxx4Kids this weekend, I thought I would update my pass the pigs game and add in the scoring and just rewrite it a little.
If you aren’t familiar with this fun little game, here’s the gist- It consists of two pigs that you roll like dice. Depending on how the pigs land, you get a particular score-
I’ve simplified my original script even a bit more and added a function to set up the roll. I’ve added the scoring in, along with information on if you roll doubles and the game will break out of the roll if a Pigout or Oinker, (referred to as a “Makin Bacon” and a “Sider” in the top image) is “rolled”.
#!/usr/bin/python3 #Pass the Pigs Game import random
def setup_roll(): print(' ') print('Your Roll is:')
def pig_pass(): for x in range(1, 3): #two dice rolls dice_roll = random.randint(1, 6) if dice_roll == 1: print('Razorback, 5 pts! If you get doubles, 20 pts!') elif dice_roll == 2: print('Trotter, 5 pts! If you get doubles, 20 pts!') elif dice_roll == 3: print('Snouter, 10 pts! If you get doubles, 40 pts!') elif dice_roll == 4: print('Leaning Jowl, 15 pts! If you get doubles, 60 pts!') elif dice_roll == 5: print('Pig Out, Back to ZERO pts and Next Players turn unless you get doubles, then you get 1 pt!') break elif dice_roll == 6: print('Oinker, Back to Zero and Next Players turn!') break setup_roll() pig_pass()
Once we’re done coding this, you can save by hitting the <Esc> key, then “:wq” to tell the vi editor to “write” and “quit”, (for those of you that are “vi newbies”.
Let’s change the permissions on our file so it’s easy to execute without power privs:
chmod 775 pig_gm.py
To execute the game, just run the following from the directory you saved the program in:
The output from the game looks like the following:
Your Roll is:
Leaning Jowl, 15 pts! If you get doubles, 60 pts!
Trotter, 5 pts! If you get doubles, 20 pts!
Your Roll is:
Trotter, 5 pts! If you get doubles, 20 pts!
Oinker, Back to Zero and Next Players turn!
Your Roll is:
Trotter, 5 pts! If you get doubles, 20 pts!
Pig Out, Back to ZERO pts and Next Players turn unless you get doubles, then you get 1 pt!
You get to add up your points unless you get an Oinker or a Pigout, (unless it’s doubles Pigout) and you can play the game just like you had the lovely plastic pigs!
See everyone at Oracle Open World soon and enjoy!
I’ve been a bit busy traveling and speaking, but I wanted to discuss the great events I’ve been lucky enough to be part of the last couple weeks.
I spoke at the INOUG back on September 17th. The user group in Indiana is incredibly welcoming and I had a great time with the wonderful attendees for my three back-to-back sessions. We discussed AWR Warehouse, ASH and AWR Mining and a new session on Optimization for EM12c and the Hybrid Cloud.
September 21st-23rd was my first visit to the great city of Raleigh, NC and ECO! I’ve always wanted to visit the location and had a great time not just because I got to hang out with friends like Jeff Smith, Ric Van Dyke, Kent Graziano, Scott Spendolini and Tim St. Hilaire, but I also received an incredibly warm welcome from the ECO attendees! Linda Hoover and her team put on a great conference and the interaction from those in the sessions were phenomenal, both during and afterwards.
I had a great joint keynote with Jeff Smith on “Empowering Your Technical Career with Social Media”. It was incredibly well received and even though the room felt like it was -50F, everyone stayed for the entire keynote. Some of the best feedback was when a woman who was working in the hotel serving food came up afterwards to tell me how much she enjoyed it and asked me some questions about what I did for a living and how to get into the tech industry.
An attendee also came up to me in the restaurant to let me know she’d only stayed for two keynotes her entire career and that ours was one of them! These kind words from these two women and the other attendees who approached us meant a lot to Jeff and I. We really appreciate the support! I also have to thank Monty Latiolais and Ray Smith for letting Jeff and I rework their social media profiles and personal branding. It was great to see it all come together. For those that attended my technical session which was a deep dive in AWR and ASH, thank you for offering me a standing room only in the largest room they had at the conference and for all the interaction.
I raced home at midnight on the 23rd to ensure I was available to do the keynote on the 24th for the IOUG Master class at….OK, let’s just say it, I’m a Denverite, it will always be Mile-High Stadium. 🙂
The event included a good amount of RMOUG folks, along with some new folks and I got to speak with Graham Thornton from EMC, too! It was a great day to be at the stadium and a great time was had by all as I spoke on Oracle Hybrid Cloud.
Everyone knows I’ve been all about educating with small computers like the Raspberry Pi. Thanks to Jake Kuramoto, I was offered the opportunity to come be part of the coaching team with the Oracle Education Foundation, specializing in teaching Raspberry Pi with Python. I helped to build some of the content and it was an awesome experience to work with the high school kids.
I only got to spend a week out of the two week project, because if I didn’t get home at least one week in October, Tim was going to come and get me! It was a dream come true for me and I look forward to volunteering with the Oracle Education Foundation in the future.
On Thursday, Jake and his team, including the impressive Mark Vilrokx, came in to demonstrate a great nerf gun powered by an Adruino micro-computer and a sensor connected to the internet. It used voice activated commands to shoot nerf ammo, even to know how many nerf bullets to shoot.
I’ll return home next week and enjoy some time with my family, my home and my dog before returning for Oracle Open World and Oak Table World for the end of October, so until then, check out the Arduino controlled nerf gun Twitter account, IOT Nerf and a shot of the great class I worked with for the week!
So as I prepare for next week, coaching with some other great folks with the Oracle Education Foundation using the Raspberry Pi, I wanted to add some fun music into my code to work with our motor mascot project. To do so, you need a few things:
If you haven’t done so recently, run an update on your Rpi:
sudo apt-get update
Now that you know your Rpi is up to date, let’s get the MPlayer software:
sudo apt-get install mplayer mplayer-gui alsa-base alsa-utils pulseaudio mpg123
If you have your Rpi hooked into a small monitor, like I do, then don’t be surprised if the mplayer application fails due to the display constraints. The rest of the code and librariesiare what we’re really interested in, so not a big deal.
Once it’s finished, reboot your Rpi:
Once it’s up, lets do a bit of code. There are a number of online FM URL’s that can be used with the mplayer, so it’s really a lot of fun. You must have WiFi access configured on your Rpi for this to run:
os.system(“mplayer -playlist http://tunein.com/radio/1FM—Absolute-Top-40-s48967/”)
Save the file as play_music.py
To run this, simply type in:
sudo python3 play_music.py
I’ve updated my script to do a few things, including blinking lights and spinning motors, but the video gives you at least a taste of the motor and the music!
Have a great Firday, folks!
So one of the things I like to do is test out a lot of my python gaming code, (as far as for the coding and syntax) on my Oracle Virtualbox image of my Raspberry Pi. Another great thing about building games on the Raspberry Pi, is a built in module called Pygame. Well, that doesn’t exist on the Raspberry Pi image and it really limits what we can do when it comes to the VNC build we play on the Oracle Virtualbox, (that’s a mouthful… :))
The first step is to first get out to all the libraries, as the ports the image is a bit locked down. At the top, click on Devices, Network, Network Settings. Add a check mark for “Cable Connected” and then click on the “Port Forwarding” settings. Update the settings to reflect what I have for the open ports, (remember, this is Oracle Virtualbox… :))
Once you’ve updated the Host and Guest Port, click OK.
As I want to stay with Python 3 as much as possible, we’re going to install it with our Vbox image with the Python 3 build. Let’s start by installing:
sudo apt-get install mercurial
Choose “Y” for both questions and proceed with the installation. There are a lot of files here, (over 500) so it will take just a few minutes to install everything. Now, we need to run the clone step:
sudo hg clone https://bitbucket.org/pygame/pygame
Once this complete, which is just a matter of seconds, again, choosing “Y” for the questions, we need to build the dependencies after we download those:
sudo apt-get build-dep pygame sudo apt-get install python3-dev sudo apt-get install python3-numpy cd pygame sudo python3 config.py
You shouldn’t run into any failures at this step, as I didn’t with my own image. If you do, you can go back to the first step and instead run:
sudo apt-get update
If all is successful at this point, then it’s time to build and install:
sudo python3 setup.py build sudo python3 setup.py install
Now we need the Alsa Sound Library that isn’t in this image. These are called by the Pygame module and come by default on Raspberry Pi, but yep, not here! You can check first to verify that they aren’t there, (if you’re curious…):
apt-cache policy alsa-base libasound2 alsa-tools
Now run the install with the following command:
sudo apt-get install alsa-utils sudo apt-get install alsamixer
You’ll now see the ALSA sounds libraries if you run the check command again.
Now you’re ready to code Pygame games on your Virtualbox image of the Raspberry Pi! 🙂
Back on August 7th, the RMOUG’s Quarterly Education Workshop, I walked everyone through using a Pibrella board to create an art or flyer project that was powered with a python script and a motor.
Today, we’re going to take that same code and reuse it with a simple robotics kit to control power and rotation speeds/time to the Insectoid. This kit, puchased from the Go! store in Flat Irons Crossing mall, was $16 and can be built in less than an hour, even for a small child. If you’re interested, you can also purchase the kit online at Amazon, but it was cheaper for me in the store to get him than online…
It requires only a small screw driver and is powered by a AAA 1.5 volt battery. With the power required to the motor, I recommend leaving the battery wired in and the device off, (Raspberry Pi will be glad to supplement the power and you’ll know if you’ve overwhelmed your power requirements to a secondary project just by the sudden cycle of the OS, so keep this in mind….)
After following the instructions and assembling the gears, the body and legs to complete the robotic insectoid, test it out with the battery and power switch. Once he tests successfully, then comes the fun part of wiring him to the Pibrella board to control him from our Raspberry Pi.
Using red and black female/male breadboard jumper wires like the ones below-
Create a long black and long red “extension” to connect the insectoid to the Pibrella board. Now, undo the cap that is connecting the battery and motor wires to the top of the Insectoid. If the battery is wired into the motor wire in a way that makes the motor wire inseparable from it, re-wrap the battery wire to the motor wire at the base, leaving just the motor battery straight. Take the motor battery, matching black to black and red to red, inserting the motor wire into the female jumper wire “extension” and ensure it’s tight. You shouldn’t need any electrical tape to secure it and it should look like the following picture when you’re finished.
You can re-secure the connections under the cap after you’ve added the connection to the female jumper, (as seen for the red, (negative) connector.
Once this is done, it’s time to “recycle” our python script. Log into the Raspberry Pi and open up a Terminal window. Review your Python script from the earlier project OR just create a new python script, (.py) in your favorite text editor and type in the following-
import pibrella import time
while true: if pibrella.button.read(): pibrella.output.e.on() time.sleep(10) pibrella.output.e.off() cleanup()
The Python code does the following:
You execute the script as we do any of our python scripts, using Python 3-
>sudo python3 <name of script>.py
A video of the run with the robotics project can be seen on YouTube.
The next step is to enhance our script and have our robot do more than just walk forward and/or stop at a certain time. We’ll want to build out a robot to have a Raspberry Pi control board ON BOARD and control his movements to turn, go in reverse and so forth.
Until next time-
So I don’t doubt that many parents are bleeding out money for kid’s school fees, supplies, clothing and other demands this time of year. How many of you are in their local Target, Walmart or other store and after filling the cart with the necessary, the kids eye up the toy aisle and start to ask for something?
Even teens are not immune and may be asking for games. If you could turn around and say to them, “If you want the game, then why don’t you build it instead of buying it?”
Now as many of you have figured out, I’m starting to build an arsenal of Raspberry Pi content to teach in classes and meetups. The following is to simulate the game “Pass the Pigs”. If you’ve ever played this popular game that uses plastic pigs in the place of dice, it required my brain to rethink how I was coding my dice games to how I would code a game that used the fall placement of a plastic pig. This demonstrated one of the greatest things about Python- I still was using the same module, but I just used it in a different way to code my new game!
So let’s say we want to code a simple roll of dice game.
#Dice Roll import random #Insert space between import and code... for x in range(1, 2): dice_1 = random.randint(1, 6) dice_2 = random.randint(1, 6) print(dice_1 + ' + ' + dice_2)
The above code will do the following:
Now to change the code and create the Pass the Pigs game, we get to use the RANDOM module again, but the code changes as we are going to use a function to tell Random what “word options” will be used instead of random numbers to return. It will then use two pigs and then will output the roll, (which is a function).
#Pass the Pigs import random pig_fall = ['Razorback', 'Trotter', 'Snouter', 'Leaning Jowl', 'Pig Out', 'Oinker'] def pick_pigs(): Pig1 = random.randint(0, len(pig_fall) -1) Pig2 = random.randint(0, len(pig_fall) -1) return pig_fall[Pig1] + ' + ' + pig_fall[Pig2] print (pick_pigs())
This code is different from the first one, even though it really ends up doing the same thing. Notice that there are six options, just like there are six sides to a die. This is really very similar to the dice game, we’ve just used different code that works more efficiently with our requirements. By execution the code, we can then play the game!
>sudo python3 <script_name>.py
Leaning Jowl + Pig Out Trotter + Pig Out Leaning Jowl + Razorback
We can use the game instructions, (can be found online) to then add up our scores for our three players-
So there you have it and next time your kids ask you for toys and games, consider getting them a Raspberry Pi instead and make it pay forward, creating projects and games with it instead!
Until next time…
There’s an old joke about the evolution of a programmer. It starts with the programmer in their infancy and typing:
Print “Hello World” and so the output returns:
The programmer continues to evolve. His coding knowledge increases and his code in the end of his evolution becomes a script of 5000 to 10,000 lines. What does the output return? You guessed it:
I often joked that I’d make a terrible developer. I over think everything, but the truth is, I may have just evolved too much and need to devolve to improve. There used to be a sign up on my door of my office years ago, put there by an Operations Manager that read-
Go away before I write an efficient script to replace you.
It wasn’t far off from the truth. My shell scripts made the world go round, but they also were built with a certain mindset design. There was almost always a wrapper shell script that called subsequent scripts to perform different tasks and arguments to do what was expected. This was the design and mindset of shell scripting I’d been taught by a great scripting teacher.
Now that I’ve been working in Python for the last four months, I’ve had to admit to myself that my mindset has to change. I need to move to the Pythonic way of thinking. What is Pythonic thinking? It is the particular style that has emerged over time trhough experience using the language by those that know it best. This challenge is also quite normal for anyone coming to Python. Doesn’t matter if the programmer is skilled at Java, C++ or Ruby Rails, they all go through it. Python is very efficient, but below, you’ll find a perfect example of how one can really work hard instead of smart, i.e. the Pythonic way.
For my latest project, after noting the lights and built in sounds for the Pibrella board add-on for the Raspberry Pi, I decided I wanted to create a gaming script that when combined with kids imagination, could be used in a variety of ways. The game, “Red Light, Green Light” was the source of the inspiration.
The requirements were as follows:
Now I created the initial script to test the process without issue. I used the Pibrella and time modules-
import pibrella import time #start game with success and green light. During green, (25 seconds) people will move as fast as want. pibrella.buzzer.success() time.sleep(3) pibrella.buzzer.off() pibrella.light.green.on() time.sleep(25) pibrella.light.green.off() pNow lets go in slow motion. Signal the yellow alarm and then light for 15 seconds of slow motion movement. pibrella.buzzer.buzz( frequency ) pibrella.buzzer.note( 1 ) #this is the frequency for the Note A time.sleep(2) pibrella.buzzer.off() pibrella.light.yellow.on() time.sleep(15) pibrella.light.yellow.off() #Now for a stop movement or red light in the game. pibrella.light.red.pulse(2,4,2,1) #we’ll make the light pulse instead of just light up pibrella.buzzer.fail() time.sleep(2) pibrella.buzzer.off() pibrella.light.red.off()
Now this seems pretty straight forward, but now I wanted to add in the logic to have random runs on times and variations of colored light sequence. I started by duplicating the script and adding in different rotations and time. I planned on six different scripts with different amount of time included in it and rotations…about 150 lines of code when I finished.
Why? Because this is how I would have built in the logic to Shell scripts. I would have had a wrapper script that would call the other scripts to run different rotations to keep the players on their toes.
What’s the problem with this logic? It’s not the Pythonic way of doing things- secondary scripts called from a main script and adds to complexity that doesn’t belong in the code. It’s also the wrong way to teach python coding and would have added confusion to the class.
So how should these requirements be coded?
The latest Python script looks very different from the first and it includes everything in one script, using three modules. I’ve added the Random module, which allows me to build out a random number generator that acts like a throw of a dice. Depending on the results, a different light and duration occurs. I chose six variations, three green, two yellow and one red. With the red, (throw on a six) there is a break to leave the execution of the script, but the code is built to run for 30 times as is.
import random import pibrella import time for x in range(1, 31): #run for 30 iterations dice_1 = random.randint(1, 6) #options, just like a die. if dice_1 == 1: pibrella.buzzer.success() time.sleep(3) pibrella.buzzer.off() pibrella.light.green.on() time.sleep(25) #green for 25 seconds pibrella.light.green.off() if dice_1 == 2: pibrella.buzzer.success() time.sleep(3) pibrella.buzzer.off() pibrella.light.green.on() time.sleep(15) #green for 15 seconds pibrella.light.green.off() if dice_1 == 3: pibrella.buzzer.success() time.sleep(3) pibrella.buzzer.off() pibrella.light.green.on() time.sleep(10) #green for 10 seconds pibrella.light.green.off() if dice_1 == 4: pibrella.buzzer.note( 1 ) #solid note for tone time.sleep(2) pibrella.buzzer.off() pibrella.light.yellow.on() time.sleep(25) #yellow for 25 seconds pibrella.light.yellow.off() if dice_1 == 5: pibrella.buzzer.note( 1 ) #solid note for tone time.sleep(2) pibrella.buzzer.off() pibrella.light.yellow.on() time.sleep(15) #yellow for 15 seconds pibrella.light.yellow.off() if dice_1 == 6: pibrella.light.red.pulse(2,4,2,1) #red, you’re done! pibrella.buzzer.fail() time.sleep(2) pibrella.buzzer.off() pibrella.light.red.off() break #escape out of the loop
This code now randomly runs different variations of green and yellow with their notifying buzzer, up to 30 times or until it results in a “6”, which then will alarm, pulse the red light and exit out of the script. No other scripts or logic is required because I coded it with the Pythonic way of thinking.
To execute the code, looks like this:
sudo python <script_name>.py
So what does this code look like when I remove the extended times in the lights so the random generations goes at an accelerated rate of change between each?
Just like this video…
Now I want you to imagine playing the game of Musical Chairs to this. Green means go fast for the time elapsed, (10, 15, 20 or 25 seconds…) Yellow requests all the players must go in slow motion, (which is also amusing for the spectators… :)) and then the red light, (and alarm) signifies everyone tries to immediately find a seat before there isn’t one left!
In a larger room, you could use it to play “Red Light, Green Light”. You could still expect the players to go in slow motion during the yellow iterations and just as in the standard game, anyone still moving when the alarm and red light go off, must return to the starting line.
The completion of the project, after working with the kids to create the code, test and verify, is then to ask them to use their imagination on how they would use the code or enhance it to play other games. The random libraries could easily be used for dice games, displaying the role and even incorporate more than one die for the game.
Until next time…
So I’m working on a lot of posts for Enterprise Manager, but I can’t post them just yet, so here’s some more Raspberry Pi love to keep you busy until then… 🙂
Many times I just want to write and test some code, but I want to do it while I’m taking a break from my day to day work- waiting for a download, in a meeting, a script is running in another window, etc., so it’s convenient to have a Virtualbox image to run Python scripts with all the libraries and modules installed. I can’t simulate my Pibrella card or other add-ons, but I can install the libraries and verify that all my code tests out syntax wise before I run it on the actual Raspi.
Now the “noobs” install of Raspian, (Debian) won’t work for a direct Vbox image. It’s made for ARM processors and Virtualbox is expecting an OS to support an X86 processor. This just means we need to be more selective in the OS version that we use, so we’re going to use Ubuntu or other supported platforms for our image, then add the Raspian on top of it. You could use an emulator like Qemu, that emulates the hardware, too, but I just want a simple Vbox image and be done with it.
If you just want to use an Ubuntu image, already built, you can locate that here and that’s what we’ll do for this example- use the pre-built image and then add what we need to it!
The OVA fill need to be extracted from the bit torrent file using 7Zip or another file management program after it’s been downloaded.
Once this is done, open up Oracle Virtualbox and choose to “import appliance” option with the file, keeping all the defaults.
The Username/Password is rpi/password and once you login, open a folder and right click, choose “Open in Terminal”. You can then change the directory from the default to debian-
cd debian ./launchDebian
Expect some odd errors to come up- this is normal for this image and can be disregarded.
Once the errors complete and the prompt stops at the “Same machine: preferring raw encoding” statement, then go back to your folder and right click again, opening a second terminal.
Type in the following:
Username/password is root/password and you’ll find that you are now working from the Raspberry Pi command line, just as if you were on the machine!
Installing the Pibrella Libraries are pretty easy. Just do the installations and you are set. Start with running the update:
sudo apt-get update
Then run the upgrade:
sudo apt-get upgrade
Now, let’s install the Pibrella modules:
sudo apt-get install python-pip sudo pip install pibrella
Once completed, now I have all the pibrella module installed and can run code. We can run a quick test, too.
import pibrella pibrella.buzzer.fail() pibrella.light.pulse(0.2) from sys import exit exit()
Save the file and then execute it:
sudo python -i pibrella_test.py
No, the lights and buzzer, or button commands won’t work on the simulator, but I can test my code to verify that syntax is correct and get it ready before moving it over to the actual Raspberry Pi!
As most folks know, I’m a Python addict, so I also want to update to Python 3 on this image.
sudo apt-get install python3
Now I have everything I need to simulate my Raspberry Pi to run scripts from my PC!
Have a great day and Pi on!
RMOUG’s Quarterly education workshop was a great event today and I appreciate everyone who came out and those who spent time with their family and their user community doing fun geeky stuff.
There were a few things I promised folks, including access to my family coding slides so anyone can do this at home. Even though I’ve included the GPIO with breadboard configuration and code in the slides, please, PLEASE consider getting the Pibrella board and code with it instead. The chance of wiring the board wrong is high for those just starting out and even I ran into this after having some extensive time with the product, so for the $15-20, it’s worth the investment… 🙂
The slides to do this hands on lab can be found here. The art project pieces to do this most effectively with the motors-
From Michaels or another hobby store:
One thing we found useful for this event- I had two images already built with all the libraries and downloads performed and installs configured. This saved a few folks- we just pushed my SDCard for the first Pi or Micro SDCard for the latest version into the slot and then the attendee could go through the full setup of their Raspberry Pi once they got home.
I also lent out my pibrella card, monitor, mice, keyboard and jump drives. In the future, I’m thinking HDMI cables and maybe HDMI to VGA adapters might be a good bonus, along with extra Raspberry Pi power cables. Many of these online stores sold the unit without the power cables and one sent an attendee home with the wrong size memory card!
After you write out all your code, one of the challenges was hooking up the motor to the pibrella board. I planned on using my own setup as the physical example, but since I’d lent out all my hardware, I didn’t have that example anymore. I’ve added the following pictures to help give a visual representation to the project.
Ensure that you note the positive and negative on the Pibrella board, plugging the positive, (red) and the negative, (black) in to the correct holes in the board. Note that your board may be active on the bottom left, (D on the Pibrella board) to the red button on the board or the upper right, (E) on the board. The active ports will show when you run your code, that line of ports will light up with a small, white light. As stated in the slides, MAKE SURE NOT to touch the wire tips to the Pibrella board circuits or the Raspberry Pi metal areas if the unit is powered up! This will cause a short and you’ll know as the unit will restart.
Now for the AWR Warehouse hands on lab. A couple people had no issues at all, but a number of folks found out that I had a problem with copies of the OVA file to “lesser quality” jump drives.
I found the issue was a corrupted listener that was giving us quite the challenge.
1. Go to $ORACLE_HOME/network/admin and open up the LISTENER.ora file.
2. You’ll see that there is either one or two databases that are now registered in the file.
You should not be able to log in, but use the following, (again, it’s still acting a bit odd, but it’s a 40G image and we’re not going to try to get people to download that across the network! :))
>sqlplus sys@AWRW / as sysdba
Enter the password and you can now log in and start the database.
Go ahead and switch to the HOL user:
sqlplus> connect awrw_hol@AWRW
And you can now work through the lab without an issue. It’s not a perfect fix, but this will get those that couldn’t run through the lab today back in business!
Thanks for coming out again to the event and I hope everyone enjoyed the afternoon at Elitches after a full morning of technical content!
Posted in Raspberry Pi