Monthly Archives: June 2018

Getting Started with Python on the Raspberry Pi

via SparkFun: Commerce Blog

“Hey, I heard that the Raspberry Pi will teach you to program!”

“I bought a Raspberry Pi because it’s cheap…now what do I do with it?”

These are the two most common phrases I hear when people are trying to figure out what to do with the Raspberry Pi. Certainly, the Pi is a great piece of inexpensive hardware that functions as a complete Linux (or other operating system) computer.

In response to the “Raspberry Pi will teach you to program” comment, I usually tell people, “Not any more than your current computer.” The Pi can’t magically upload programming knowledge to your brain (yet).

alt text

That being said, the Raspberry Pi can be a fun learning environment for individuals and schools thanks to several factors:

  • It’s affordable
  • If you break something in software, it’s easy to flash a new image
  • GPIO pins are broken out, which allows you to control hardware devices

Python has been gaining in popularity as a beginner-friendly-yet-still-powerful programming language over the past few years (according to several indexes like TIOBE and PYPL). Many schools are switching to Python to teach students as their first language. It’s approachable due to its script-like nature, but it can be used to teach more advanced concepts like polymorphism.

As a result, the Raspberry Pi can be a perfect platform for learning Python. There are plenty of books, websites and videos out there that can help you learn Python. However, we find there is something special about controlling a piece of hardware (spinning a motor, lighting an LED, taking a temperature reading) through programming. So, we’ve put together a guide to help you get started controlling hardware with Python on the Raspberry Pi:

New!

Python Programming Tutorial: Getting Started with the Raspberry Pi

June 27, 2018

This guide will show you how to write programs on your Raspberry Pi using Python to control hardware.

The raspberry-gpio-python module thankfully makes controlling pins super easy. Once you have the basics down (toggling pins, reading pin states, UART, SPI, I2C), you can control a whole suite of hardware, and the fun begins there. Robotics, IoT sensors, home automation projects, etc. become attainable.

What other combination of Python, Raspberry Pi and hardware projects/concepts would you like to see? Let us know in the comments!

comments | comment feed

Track your speed and distance while skateboarding

via Raspberry Pi

Fight the urge to chant the Avril Lavigne song as you cruise the streets on Pieter Thomas’s speed- and distance-tracking skateboard.

Speed and distance tracking Raspberry Pi skateboard

Instant approval

“That is sweet!” exclaimed Ben Nuttall when I shared this project on the Raspberry Pi Slack channel. And indeed it is — a simple idea, perfectly executed, resulting in a final product that actually managed to coax a genuine and positive response from Ben!

Prove your worth ☑

Project creator Pieter Thomas, a student at Howest Kortrijk University, needed to show off his skills by building a ‘something’ for his course. His inspiration?

I came up with this idea because I like to skate and cruise around. While I’m cruising, it would be handy to see how much distance I’ve travelled and see my speed.

So he decided to incorporate an odometer, a speedometer, and an RFID reader into a skateboard to produce this neat build.

Make and skate

While Pieter has an Arduino manage the onboard RFID reader, he’s put a Raspberry Pi 3 in charge of everything else, including the speed and distance readings taken with the help of a hall effect sensor (a transducer that uses magnetic fields to manage voltage output).

Speed and distance tracking Raspberry Pi skateboard

Pieter added the RFID reader to identify different users, with databases allowing for session data collection — perfect for time and speed challenges among friends!

Home-brew casing

All the electronics live in a Tupperware-like container that Pieter screwed to the bottom of the board. Holes in the deck display an LCD screen, a potentiometer, and a buzzer.

Speed and distance tracking Raspberry Pi skateboard

To allow speed and distance calculations, Pieter drilled a hole into one of the wheels and inserted a magnet. Once per wheel rotation, the hall effect sensor recognises the passing magnet. The build records the time taken between passes, computes the speed and distance covered, and shows them on the LCD screen.

Pieter’s Instructables project page goes into a lot more detail of how to build your own skate-o-meter. If you’ve used a Pi for your skateboarding project, make sure to let us know!

Skateboard + Pi

Other impressive Raspberry Pi–based board builds include Tim Maier’s motorised skateboard, aka the first blog post I ever wrote for Raspberry Pi, and Matt ‘The Raspberry Pi Guy’ Timmons-Brown’s 30kmph longboard, aka the project that resulted in this video of Raspberry Pi’s Director of Software Engineering:

Sk8r Pi ft. The Raspberry Pi Guy… and Gordon

The Raspberry Pi Guy popped into Pi Towers to show off his new creation. While skating up and down the office on his Pi-powered skateboard, our Director of Software Engineering, Gordon Hollingworth, decided to have a go.

The post Track your speed and distance while skateboarding appeared first on Raspberry Pi.

Shiny new software for the Jrk G2 USB Motor Controllers with Feedback

via Pololu Blog

I am happy to announce that we have released version 1.2.0 of the configuration software for the Jrk G2 USB Motor Controllers with Feedback.

This release contains a large number of new features for our graphical user interface (GUI) software that let you have more information and control while you are setting up a feedback system with the Jrk.

The graph window received the most striking update: you can now use the mouse to vertically move and zoom the different plots independently of each other. You can change the colors of the plots and save your settings to a file so you don’t have to redo them the next time you start the utility. Colored indicator arrows appear at the top and/or bottom of the graph if one of the values you are plotting is too high or low to be plotted.

The variables shown in the status tab can now be moved into their own, separate window, so you can see them at all times without having to switch back to the status tab. Similarly, the “Manually set target” interface is now visible from every tab, so you can quickly test your feedback system after changing any setting. We added a “Center” button that sets the Jrk’s target to 2048, and we added a moving red dot to the target slider that shows the scaled feedback if feedback is enabled. If feedback is not enabled, the dot is green and shows the duty cycle instead.

The “Apply settings” button now has a blue background and a label to its left when it is enabled, to make it more obvious that you should apply your settings.

The main window and the variables window in the Jrk G2 Configuration Utility (version 1.2.0).

A brief history of Jrk software development

We developed the software for our original Jrk 21v3 and Jrk 12v12 controllers back in 2009. We used the C# language and the WinForms GUI API from Microsoft since that is what we were familiar with, but unfortunately those choices basically locked us into only having the software work on Windows. While you can compile and run C# code on Linux and macOS using Mono, and Mono does have an implementation of the WinForms API, that WinForms implementation was far from adequate. It worked on x86 Linux machines, crashed immediately on ARM Linux machines, and kind of ran but was totally unusable on macOS machines. I reported a few bugs to the Mono project, and the only response I got was that WinForms is no longer being developed actively. We never released Jrk software for Linux, though we did release Maestro and Simple Motor Controller software for x86 Linux using Mono. People have asked us many times over the years about running our software on a Raspberry Pi, and for our C#/WinForms GUI software we always had to tell them that it was not possible because there was no good implementation of the WinForms API for that platform.

Starting with the Wixel in 2011, we switched to using C, C++, and Qt for our configuration software. Qt is a giant cross-platform C++ library with many components. For us, the most important component is Qt Widgets, which makes it easy to develop a cross-platform GUI with the standard elements that people expect, like windows, menus, buttons, checkboxes, and text fields. There are wrappers for accessing Qt in different languages, but we chose to write our GUI software in C++ so that it can directly access Qt, and because C++ code is easier to deploy than a lot of other languages that might require a virtual machine or interpreter. Qt works well on Windows, macOS, and Linux – including on the Raspberry Pi. While we sometimes encounter bugs in Qt or overly-rigid APIs that lack important features, we are usually able to work around those issues and get a good result.

Along with C++ and Qt, we use the C language to write low-level libraries for actually talking to the USB devices. The upper layer of these libraries takes device-specific commands like “set target to 2800” and translates them into USB commands. The lower layer takes the USB commands and passes them to an appropriate USB API provided by the operating system. This is a nice way to split up the software: the device layer knows about the device but doesn’t know about the operating system, and the USB abstraction layer knows about the operating system but doesn’t know about the device.

The Wixel software developed in 2011 used its own minimal USB abstraction layer written in C. The first versions of p-load, developed in 2014 for our P-Star 25K50 Micro, did something similar. In 2015, I built on the lessons learned from these earlier projects to develop a much better USB abstraction library called libusbp. This new library has been working great for us since then, and powers all of the USB communication in the latest versions of p-load, the Pololu USB AVR Programmer v2 software, the Tic software, and the Pololu Jrk G2 software.

In 2017, I developed another piece of the stack: nixcrpkgs. The nixcrpkgs project solves the problem of reliably compiling our portable C/C++ source code into actual executables and installers that work on a variety of different systems. With nixcrpkgs, I can compile our software for Windows, macOS, and Linux (32-bit, 64-bit, and ARM) by just running a single command on one computer. It allows me to control the exact versions of all the dependencies that go into the software. I no longer have to worry about the versions of tools and libraries installed on my development machines. I also do not have to worry about the software installed on the end user’s machine: software compiled with nixcrpkgs uses static linking so all of its dependencies (except for certain things provided by the operating system) are linked directly into the executable. The download for the Jrk G2 software for the Raspberry Pi generated by nixcrpkgs is only 6 MB (compressed), and it installs just 4 files.

Prior to nixcrpkgs, we only provided binary downloads for Windows and macOS. It was difficult to produce these downloads because we relied on third-party software distribution systems like MSYS2 and Homebrew to provide binary versions of the libraries we depended on, and we didn’t have much control over those systems. We required Linux users to compile the software and its dependencies (like libusbp) themselves. Compiling software from source can be a pretty error-prone process: we strive to make our software portable, but it’s hard to test enough combinations of compiler and library versions to avoid all the issues that might come up.

The Jrk G2 software is open source and comes with build instructions for many platforms. I am hoping that this will allow people to do cool things in the future, such as translating the GUI text into their native language, adding buttons to perform custom commands, or using the code in their own software to control the Jrk. It should also provide some confidence that you will be able to use the Jrk in long-term applications and recompile the software for future operating systems.

You can download the new software from the Jrk G2 Motor Controller User’s Guide or the “Resources” tab on a Jrk G2 product page. If you need help using the software or troubleshooting your system, please post on our forum. If you have feedback or additional feature requests for the software, let us know in the comments.

I’ve Got a Bike – You Can Ride it if You Like

via SparkFun: Commerce Blog

Here at SparkFun, we love bikes. On any given day at our headquarters you’ll find big bikes, little bikes, fold-up bikes and tricycles. We even have a couple unicycle riders, for those of you who think two wheels is just one too many. It doesn’t stop there; we also like riding our bikes together!

In fact, SparkFun has participated in the past three years of the National Bike Challenge. This past May, nine of our staff members signed up to track their rides and participate in the event. Those nine individuals logged over 900 miles in 128 riding sessions! That’s a lot of pedaling!

A team that rides together, stays together!

A team that rides together, stays together!

With all this bike activity, we found we were running out of space for people to park their bikes. The space was just not working for our needs, so a small group of SparkFun folks joined together to build out what we have called “The Spoke House”! Our goal for The Spoke House was to create a warm and inviting space that welcomes our staff as they enter the building. We tried to keep the project low-cost by using supplies we already had. In a matter of a few days, we really began to see a transformation!

The Spoke House, before

The Spoke House, before

The Spoke House, after

The Spoke House, after

The bikes are hung from thick plywood planks that are mounted to the studs of the wall. A tool bench is stocked with all the gear needed to fix a flat or change out a bottom bracket. And some creative paint and signage is being installed to brighten up the mood and really tie the room together.

As we continue to iterate on this space, we plan to include more SparkFun electronics in the space, like a sign with interactive spinning gears using a RedBoard and an Ardumoto to bring interactive art installations, and an plan to brighten the space with addressable LEDs, to bring color and excitement to the walls.

Working on some bike repairs

Working on some bike repairs

Our next event is Bike to Work Day, on June 27th. What has your workplace done to support alternative forms of transportation? Tell us in the comments!

comments | comment feed

Tim Peake congratulates winning Mission Space Lab teams!

via Raspberry Pi

This week, the ten winning Astro Pi Mission Space Lab teams got to take part in a video conference with ESA Astronaut Tim Peake!

ESA Astro Pi students meet Tim Peake

Uploaded by Raspberry Pi on 2018-06-26.

A brief history of Astro Pi

In 2014, Raspberry Pi Foundation partnered with the UK Space Agency and the European Space Agency to fly two Raspberry Pi computers to the International Space Station. These Pis, known as Astro Pis Ed and Izzy, are each equipped with a Sense HAT and Camera Module (IR or Vis) and housed within special space-hardened cases.

In our annual Astro Pi Challenge, young people from all 22 ESA member states have the opportunity to design and code experiments for the Astro Pis to become the next generation of space scientists.

Mission Zero vs Mission Space Lab

Back in September, we announced the 2017/2018 European Astro Pi Challenge, in partnership with the European Space Agency. This year, for the first time, the Astro Pi Challenge comprised two missions: Mission Zero and Mission Space Lab.

Mission Zero is a new entry-level challenge that allows young coders to have their message displayed to the astronauts on-board the ISS. It finished up in February, with more than 5400 young people in over 2500 teams taking part!

Astro Pi Mission Space Lab logo

For Mission Space Lab, young people work like real scientists by designing their own experiment to investigate one of two topics:

Life in space

For this topic, young coders write code to run on Astro Pi Vis (Ed) in the Columbus module to investigate life aboard the ISS.

Life on Earth

For this topic, young people design a code experiment to run on Astro Pi IR (Izzy), aimed towards the Earth through a window, to investigate life down on our planet.

Our participants

We had more than 1400 students across 330 teams take part in this year’s Mission Space Lab. Teams who submitted an eligible idea for an experiment received an Astro Pi kit from ESA to develop their Python code. These kits contain the same hardware that’s aboard the ISS, enabling students to test their experiments in conditions similar to those on the space station. The best experiments were granted flight status earlier this year, and the code of these teams ran on the ISS in April.

And the winners are…

The teams received the results of their experiments and were asked to submit scientific reports based on their findings. Just a few weeks ago, 98 teams sent us brilliant reports, and we had the difficult task of whittling the pool of teams down to find the final ten winners!

As you can see in the video above, the winning teams were lucky enough to take part in a very special video conference with ESA Astronaut Tim Peake.

2017/18 Mission Space Lab winning teams

The Dark Side of Light from Branksome Hall, Canada, investigated whether the light pollution in an area could be used to determine the source of energy for the electricity consumption.

Spaceballs from Attert Lycée Redange, Luxembourg, successfully calculated the speed of the ISS by analysing ground photographs.

Enrico Fermi from Liceo XXV Aprile, Italy, investigated the link between the Astro Pi’s magnetometer and X-ray measurements from the GOES-15 satellite.

Team Aurora from Hyvinkään yhteiskoulun lukio, Finland, showed how the Astro Pi’s magnetometer could be used to map the Earth’s magnetic field and determine the latitude of the ISS.

@stroMega from Institut de Genech, France, used Astro Pi Izzy’s near-infrared Camera Module to measure the health and density of vegetation on Earth.

Ursa Major from a CoderDojo in Belgium created a program to autonomously measure the percentage of vegetation, water, and clouds in photographs from Astro Pi Izzy.

Canarias 1 from IES El Calero, Spain, built on existing data and successfully determined whether the ISS was eclipsed from on-board sensor data.

The Earth Watchers from S.T.E.M Robotics Academy, Greece, used Astro Pi Izzy to compare the health of vegetation in Quebec, Canada, and Guam.

Trentini DOP from CoderDojo Trento, Italy, investigated the stability of the on-board conditions of the ISS and whether or not they were effected by eclipsing.

Team Lampone from CoderDojo Trento, Italy, accurately measured the speed of the ISS by analysing ground photographs taken by Astro Pi Izzy.

Well done to everyone who took part, and massive congratulations to all the winners!

The post Tim Peake congratulates winning Mission Space Lab teams! appeared first on Raspberry Pi.

Make your own custom LEDs using hot glue!

via Raspberry Pi

Tired of using the same old plastic LEDs in your projects? It’s time to grab a hot glue gun and some confectionary moulds to create your own custom LEDs!

Custom hot glue LED Custom hot glue LED Custom hot glue LED

Blinky LEDs!

Lighting up an LED is the standard first step into the world of digital making with a Raspberry Pi. For example, at our two-day Picademy training events, budding Raspberry Pi Certified Educators are shown the ropes of classroom digital making by learning how to connect an LED to a Pi and use code to make it blink.

Anastasia Hanneken on Twitter

Blinking LED Light @Raspberry_Pi #picademy! https://t.co/zhTODYsBxp

And while LEDs come in various sizes, they’re all pretty much the same shape: small, coloured domes of plastic with pointy legs that always manage to draw blood when I grab them from the depths of my maker drawer.

So why not do away with the boring and make some new LEDs based on your favourite characters and shapes?

Making custom LEDs with a whole lotta hot glue

The process of creating your own custom LEDs is pretty simple, but it’s not without its risk — namely, burnt fingertips and sizzled LEDs! So be careful when making these, and supervise young children throughout the process.

The moulds

I used flexible ice cube trays, but you could also use silicon chocolate moulds. As long as the mould is flexible, this should work — I haven’t tried hard plastic moulds, so I can’t make any promises for those. Also be sure to test whether your mould will withstand the heat of the hot glue!

Check your LEDs

Before you submerge your LEDs in hot glue, check to make sure they work. The easiest way to do this is to set up a testing station using a Pi, a breadboard, some jumper wires, and a resistor. To save having to write code, I used the 3V3 pin and a ground pin.

make your own custom LEDs for Raspberry Pi

Remember, the shorter of the two legs connects to the ground pin, while the longer goes to 3V3. If you mix this up, you’ll end up with a fried LED like this poor LEGO man.

make your own custom LEDs for Raspberry Pi

Everything isn’t awesome.

Once you’ve confirmed that your LED works, bend its legs to make it easier to insert it into the glue.

Glue

Next, grab a hot glue gun and fill a mould. The glue will take a while to cool, so you have some time to make sure that all nooks and crannies are filled before you insert an LED.

make your own custom LEDs for Raspberry Pi

Tip: test a corner of your mould with the tip of your glue gun to check how heat-resistant it is. One of my moulds didn’t enjoy heat and began to bubble.

Once your mould is properly filled, push an LED into the glue, holding on to the legs to keep your fingertips safe. Have a wiggle around to find the bottom and sides of your mould and ensure that your LED is in the centre.

make your own custom LEDs for Raspberry Pi

Pick a colour best suited to your mould. You could try using multiple LEDs on larger moulds to introduce more colours!

You may notice that the LED tries to sink a little and the legs begin to drop. Keep an eye out and adjust them if you need to. They’ll stop moving once the glue begins to set.

make your own custom LEDs for Raspberry Pi

These took about ten minutes to cool down.

Be patient

Don’t rush. The hot glue will take time to cool down, especially if you’re using a larger mould like the one for this Stormtrooper helmet.

Custom hot glue LED

Here I used a gumdrop LED, which is larger than your standard maker kit LED.

You’ll know that the glue has set when the shape pulls away easily from the mould. It should just pop out when its ready.

make your own custom LEDs for Raspberry Pi

Pop!

Light it up

Test your new custom LED one more time on your testing rig to ensure you haven’t damaged the connections.

make your own custom LEDs for Raspberry Pi

As with all LEDs, they look better in the dark (and terrible when you try to take a photo of them), so try testing them in a dim room or at night. You could also use a box to create a small testing lab if you’re planning to make a lot of these.

Star Wars custom LEDs Raspberry Pi

Now it’s your turn

What custom LED would you want to make? How would you use it in your next project? And what other fun hacks have you used to augment tech for your builds?

The post Make your own custom LEDs using hot glue! appeared first on Raspberry Pi.