After many years working with and teaching others about the Arduino development platform, it became apparent that there needed to be a useful guide to get people started in the world of AVR microcontrollers – used in Arduino and other development environments. The great people at No Starch Press agreed and we are now proud to have published “AVR Workshop – A Hands-On Introduction with 60 Projects“.
AVR Workshop is written for several groups of people:
Those of you who have used an Arduino but now want to learn how to harness the underlying AVR microcontrollers without the layer of Arduino abstraction.
Anyone interested in electronics and wanting to start with using microcontrollers.
Students who are going to learn how to use AVR microcontrollers in their coursework.
People tasked with making devices based around 8-bit AVR microcontrollers and don’t know where to start
AVR users who would like a neat reference on using popular devices with their microcontrollers and don’t have all day to scour the Internet for tested, quality resources.
You. Yes, you. Learning is for a lifetime, so why not get started with the world of electronics and microcontrollers? Or give a copy to someone who enjoys learning about technology?
Anyone can use this book. You don’t need any previous experience in electronics, programming, or making things. AVR Workshop will take you step-by-step from the beginning including installation of the required software, explain electronics when required, teach you the required coding and walk you through examples including sixty projects enabling you to harness popular 8-bit Microchip AVR microcontrollers.
Once you’ve worked through the book – you will have the knowledge, experience and confidence to branch out on your own and build complex projects, work with other Microchip AVR microcontrollers – and find success in this fascinating field. You will also have a useful reference tool that you can refer to when making your own devices.
Unlike other books or resources found online, I don’t hide any details from you in order to simplify things. Important functions aren’t hidden away in software libraries – instead you’ll learn how to control the microcontroller down to the register level to control all sorts of useful devices. Instead of relying on others – you’ll learn how to write your own libraries, so you can make your own parts and devices easier to work with.
You don’t need to spend a fortune, in fact I’ve written AVR Workshop to be as economical as possible for you, the reader. The required software is small, free to download and can operate on Linux, MacOS or Windows using machines that date back almost ten years. You don’t need any cloud-based tools or the latest i7 or M2-based computer… almost any will do.
AVR Workshop is printed using a convenient lie-flat technology, so you can have the book open to your side and not worry about the pages flapping about and losing your position while working on your projects. All the required code is included in the book, however you can also download them along with a list of parts and supplier information from the book’s website.
The Microchip AVR series of 8-bit microcontrollers are, in my opinion, an inexpensive and most approachable way of learning about electronics and microcontrollers – and open up a whole new world of creativity or even the pathway to a career in technology. A copy of AVR Workshop is the best guide to start anyone in this world.
To learn more about AVR Workshop, you can review the table of contents, download a sample chapter, code and parts list and order copies for yourself and others from the No Starch Press online store. Orders from No Starch Press also include a free electronic copy so you can get started immediately.
After a long period of development, we’re really happy to pass on the announcement that version 2.0.0 of the Arduino IDE is now available. Not only is it a more usable and practical development environment, there’s also some new features such as seamless cloud integration (which you are not forced to used) which makes moving between machines easy. From the arduino website:
We’re pleased to announce that as of today Arduino IDE 2.0 has moved to stable and is available for download. Since the launch of the Beta version back in Spring 2021, the feedback received from the active Arduino community has enabled us to focus on what’s meaningful to the widest user-base. It carries a modern editor and provides a better overall user experience thanks to a responsive interface and faster compilation time.
Over and above the core features (we’ll get into those in more details later) the IDE 2.0 benefits from a number of enhancements and additional support. The Serial Monitor and Plotter can be used together, enabling users to have two viewports onto their data output. Before you had to choose between text and graphs, whereas now you can have both.
As well as the refreshed User Interface that provides a more intuitive experience whilst using Arduino IDE 2.0, speed is of the essence. An Arduino-optimized code-completion and code-assist within the language server, help you write code quickly and spot errors as you type. The enormous amount of user feedback allowed us to identify the weakest spots such as code assist and completion, serial output, loading and compilation time. We made it all better now.
A special mention goes out to Paul Stoffregen who has provided enormous feedback to the IDE development team and been actively developing the initial support for advanced third-party platforms such as Teensy for IDE 2.0 (currently experimental).
If you haven’t already given the new IDE 2.0 a try, here are just a few of the key features…
Autocomplete during sketch editing
While typing, the editor can suggest the autocompletion of variables and functions according to your code and the libraries you included:
When right-clicking on a variable or a function, a contextual menu will provide navigation shortcuts to jump to the line (and file) where they are declared:
Dark Mode
If your eyes are feeling the strain you can quickly change settings and switch to Dark Mode. Some of you may have used this during the Beta, but our design team has reworked the entire Dark Theme to make it more consistent, beautiful and easy on the eye.
Never lose a sketch keeping them safely at Arduino Cloud
For people who work on multiple computers or want to store their Sketches securely in the Cloud, the Remote Sketchbook integration is a really useful feature.
Easily switch from one computer to another and keep working. If you don’t have Arduino IDE 2.0 installed on all your machines, just open the Arduino Web Editor and you can code from your browser in the online IDE with access to all your sketches and libraries. There’s no need to worry about losing your sketches either, with Remote Sketchbook you only need one click and they will be pushed securely to the Arduino Cloud.
Work offline and sync later, simply bring your sketch down from the Cloud, edit offline and when you are back online click on “Push” and all your changes will be uploaded, meaning all your sketches will always be up-to-date and ready to use.
Serial Plotter
The IDE 2.0 features a richer Serial Plotter that is a versatile tool for tracking different data and variables which are received from your Arduino board. The Serial Plotter is a really useful visual tool that will help you to understand and compare your data points better. It can be used for testing and calibrating sensors, comparing values and other similar scenarios.
In-app updates
Our users have always been accustomed to receiving notifications when new boards’ support or libraries updates were available, and IDE 2.0 is no exception. As a plus, the IDE can now itself be updated when a new version is available, so no need to head to the downloads page anymore: click the button and get the latest and greatest.
The new IDE is based on the Eclipse Theia framework, which is an open source project based on the same architecture as VS Code (language server protocol, extensions, debugger). The front-end is written in TypeScript, while most of the backend is written in Golang.
Click here to download the new IDE for your system now. Time certainly flies along, it feels like yesterday when we switched from the old Arduino IDE to version 1.0. Kudos to everyone at the Arduino team and all the beta testers for the works and effort.
If you’re interested in Arduino and want to get started – please purchase a copy of Arduino Workshop, 2nd Edition – a hands-on introduction to electronics and Arduino with 65 projects. It’s written for the complete beginner – you won’t need any other book or website, and by the end you’ll have the knowledge and skills to turn a wide range of ideas into life.
This is a rewrite of a project I created in 2010 which brought me a lot of joy, so I hope you enjoy it too.Please read the entire article before starting your own. You can still make it today, the parts are easily available.
I’ve always enjoyed making Arduino-powered clocks, however over time they tended to become increasingly complex. So to counter this, allow me to introduce you to “Blinky” the one-eyed clock:
It reminds me of the giant killer orb “Rover” from “The Prisoner“… Using a minimal Arduino bootrom system, a DS1307 real time clock IC and an RGB diffused LED, you can make a clock that blinks the time, using the colours of the LED to note different numerical values.
For example, if the time is 12:45, the clock will blink red 12 times, then show blue for a second (think of this as the colon on a digital clock) then blink four times in green (for forty minutes), then blink three times in red for the individual minutes.
If there is a zero, blink blue quickly. Then the clock will not display anything for around forty seconds, then repeat the process. Here he (she, it?) is blinking the time:
Setting the clock is simple. It is set to start at 12:00 upon power up. So for the first use you have to wait until about five seconds before midday or midnight, then power it up. To save cost it doesn’t use a backup lithium battery on the real-time clock IC, but you could add one if required. So let’s get started.
The first thing to do was test the RGB LED for brightness levels, so I just connected it to the digital output pins of my Arduino-compatible board via suitable current-limiting resistors. Red, green and blue to D9, D10 and D11 respectively. Each LED is going to be different, so to ensure maximum brightness without causing any damage you need to calculate the appropriate resistor values.
This is quite easy, the formula is: resistor (ohms) = voltage drop / LED current So if you have a 5V supply, and LED that needs only 2 volts, and draws 20 milliamps (0.2 amps) , the calculation will be: resistor = (5-2)/0.02 = 150 ohms. To be safe I used 180 ohm resistors. The LED was tested with this simple sketch:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It was interesting to alter the value of d, the delay variable, to get an idea for an appropriate blinking speed. Originally the plan was to have the LED in a photo frame, but it was decided to mount a ping-pong ball over the LED for a retro-style look. Here is a short video of the result of the test:
If you are going to use a ping-pong ball, please be careful when cutting into it with a knife, initially it may require a lot of force, but once the knife cuts through it does so very quickly.
Now it was time to develop the sketch to convert time into blinks. The sketch itself is quite simple. Read the hours and minutes from the DS1307 timer IC; convert the hours to 12 hour time; then blink an LED for the number of hours, display another colour for the colon; divide the minutes by ten and blink that in another colour; then the modulus of minutes and ten to find the individual minutes, and blink those out. Here is the first test sketch:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Finally, the code was tested using the Arduino-compatible board and my home-made DS1307 real time clock shield (hey it was 2010, DS32xx were expensive). It is best to use existing hardware while testing, before committing to purchasing new hardware and so on. So here it is on the breadboard:
Here is the prototype in action:
If you’re wondering why the videos are potato-cam quality, smartphones couldn’t record using 4K Ultra HD in 2010.
But perhaps the first version was a little bland. By using analogWrite() we can control the brightness of the LED segments. So I’ve added two more functions, whiteGlow() and blueGlow(); whose purpose is to make the display “glow” by increasing then decreasing the brightness.
And I’ve scaled back the amount of blinking, to make blinky less obvious. So now the display will glow white to announce the forthcoming display of time, wait a second, blink the time (with a blue glowing colon) then stay dark for ten seconds before repeating the process. Here is a quick demonstration of this display style:
Here is the sketch for the above demonstration, and the final one I will use with the hardware prototype:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Once happy with the sketch, I put a fresh ATmega328P-PU with Arduino bootloader in the board and programmed it with the sketch, to be used in the final version. The next step is to build my own hardware. The last hardware unknown is the amount of current the circuit draws. Once I know this the correct voltage regulator and power supply can be decided upon.
I had a fair idea it would be less than 100 milliamps, so I put a 6V battery onto supply duty via a 78L05 5V regulator (data sheet), and recorded the result:
So it varies, between 20.5 and 46 mA. As it only reaches 46 mA for a short time, we could consider the constant draw to be averaged out at 30 mA. I really want this to be able to run from a battery, but without having an external lead-acid battery lurking around, it will need a plug-pack with an output voltage greater than 7V DC.
Another alternative would be to run it from a USB socket, a nice source of 5V. If doing so, there wouldn’t be a need for the 78L05 regulator. Which brings us to the circuit diagram, which includes the power regulator. I’ve also altered the resistors to suit the RGB LED used, your values may be different:
And since it’s 2022, not 2010 – I’ve replaced the DS1307 circuit with a RTC module. Y1 is a three pin 16MHz ceramic resonator, we used those in 2010 as they were cheaper and easier than a crystal and two 22pF capacitors.
The circuit does not allow for uploading code, so you will need to program the microcontroller on another Arduino or compatible board, then transfer it to the blinky circuit board as described above. At this stage you should test it again – but using a solderless breadboard. In doing so you can make final hardware checks, and generally make sure everything works as it should. This is also a good stage to double-check you are happy with the display behaviour, default time and so on.
Used the Duemilanove as a lazy 5V for testing.
Time to solder up the circuit on some stripboard. Blank stripboard varies, but luckily I found this and a nice box to hold it in:
Stripboard does vary between retailers and so on, so you will need to work out the layout with your own board. In doing so, please double-check your work – follow the layout against the schematic and so on.
Have a break, then check it again. There is nothing worse than soldering away to realise you are one strip too far over or something. My hand-eye coordination is not the best, therefore my soldering isn’t pretty, but it works:
Note that the images above are using the 2010 circuit – which had a DS1307 sub-circuit.
One would say that there is a good argument for making your own PCBs… and I would agree with that. In 2010 it wasn’t that easy or inexpensive. Now you have KiCAD and Chinese PCB fabs tripping over themselves to give you cheap boards.
The LED is soldered to some short leads to give it a bit of play, and some heatshrink over the legs to keep them isolated:
And finally, to add a DC socket to feed blinky some power:
The last thing was to check the soldering once more under natural light, to check for bridges or shorts, then have a cup of tea. Upon my return I drilled out a hole in the enclosure lid for the LED, and one one the side for the DC socket, and fitted the lot together… and success! It worked.
I hope you enjoyed making this or at least reading about it. If you find this sort of thing interesting, please consider ordering one or both of my books from No Starch Press, or other book sellers:
Working from home – either you enjoy it, or doing so has been thrust upon you. As a world-class introvert I’ve always enjoyed being self-employed and working from my own office. However others do not, as they have missed out on the activity and interacting with other people in their workplace.
I was recently asked by an associate to make up a simple messaging system, that would allow them to indicate their work status and also request a coffee or whatnot from their husband, which has resulted in the simple messaging system described in this article – which you can build too.
Being somewhat lazy efficient I needed a simple WiFi-based solution that allowed for simple control of some digital output pins from a web page. A bit of research resulted with the Particle Photon, a compact WiFi-enabled microcontroller that includes all the Internet-connectivity without any hard work or recurring payments.
After consultation it was decided that there should be five messages that can be sent and will need to be indicated to the receiver:
“I’m in a meeting, do not disturb”
“I’m working alone, so I can be disturbed”
Bring coffee
Bring Water
“I’ve finished work for the day”
So that would need the control of five LEDs, and a buzzer to alert the receiver of new messages. Six digital outputs in total to be controlled remotely. Easily done with the Photon.
All the digital outputs on the Photon are 3.3V, and you can power the lot via the micro USB socket. Now let’s get started. I’ll go through the hardware first, then the software and connectivity.
USB power supply to micro USB plug to power system.
The whole thing is a minimalist design, as shown below:
The PCB shown in this article was made for a buzzer with 16mm between the pins, as it was available locally. If soldering is new to you, or you need a refresher – watch Dave Jones’ video.
This is a simple circuit you can knock out on a solderless breadboard or your own PCB with KiCAD). Click here for the Photon KiCAD library. Click here if you want the gerber files to order your own PCB. You can view the gerbers using tools such as gerblook.
At the time of writing this I have a few PCBs left over… if you live in Australia I’ll send you one for free – email admin@tronixstuff.com.
In my infinite wisdom I forgot to get some inline header sockets (as you don’t really want to directly solder the Photon to the PCB). However having hundreds spare, a work around was to use six 8 pin IC sockets, and trim one side of the pins off from each socket. Which worked …well enough:
Fitting the rest of the parts was a doddle, and resulted with the following board:
The messages were purposely not printed on the PCB silkscreen, instead all that white space is for the users to apply their own labels – as they may want to change the messages later on.
The M3 threaded spacers and nuts are fitted to the holes on the PCB to give it some legs to stand up on. So now that the hardware is finished, it’s time to get all this working with the code and connectivity.
Software and Connectivity
There are a few steps for you to complete in order to build this system, and I’ll run through them in order now.
First, follow the instructions provided by Particle which will involve you setting up a Particle account, registering and testing your Photon. During this process you will be given your “device ID” – save this as you’ll need it later. It will also save the WiFi access point details into the Photon, so do this step using the WiFi network that will host the messaging system.
Next, install the Particle CLI (Command Line Interface). It is available for Windows, Linux and MacOS. This takes about five minutes, so get up and have a stretch.
Now you need an access token, a unique identifier for your Particle account. Open the terminal on your computer and run the command “particle token create –never-expires“. You’ll be prompted for your Particle account email address and password, then presented with the token (the long random string of text). Save the token for later.
I’ve blocked out my email address and part of the token to keep troublemakers at bay.
The next step is to build the web page that contains the buttons to be pressed to send the required messages. Open a text editor and save the following as an HTML file:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Enter your access token and device ID as noted in the HTML file. Just for the record, this system is incredibly insecure and shouldn’t be used for anything of any consequence, so if you modify this to control your door locks or alarm system, that’s on you.
You don’t need to be an expert on HTML, however if you’re not sure about it check out this great HTML tutorial site.
Now open the file using a web browser, and make it a bookmark for the user to easily fine. You will be presented with a simple interface:
You can easily change the text on each button, just edit the HTML and save the file. Now review the HTML, and note that for each button there’s the text (for example):
onclick=”ledControl(‘D1On’)”>Working Alone.
This snippet will send the text “D1On” back to the Photon when the button “Working Alone.” is pressed. The idea is that we need all the buttons to send back a unique message to the Photon, so it knows what to do with the LEDs and/or buzzer. Take note that each button press sends a different piece of text back to the Photon.
Moving on, we now need to enter and upload the code to the Photon. In a web browser, visit https://build.particle.io/build/new. You may need to log in to your Particle account during this process. After a moment, you’ll be presented with a text editor that may look familiar to anyone working with Arduino. Photon code is based off the Arduino plaform, so Arduino users or AVR C users will have a head start.
Give your project a title, then copy and paste the following code into the editor:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This code configures the digital output pins for the LEDs and buzzer from lines 5 to 10, which are then set to outputs from lines 15 to 20. We then turn them all off from lines 27 to 32, so every time the Photon is reset or turned on after a power off, no LEDs or the buzzer are on.
On line 23 we have the following:
Particle.function("led",ledToggle);
This the link between the code on the HTML page you created earlier, and the function starting from line 70 in the Photon code. “led” is linked in the HTML line with “particle.callFunction”, and “ledToggle” is the function in the Photon code.
So whenever a button is pressed, the message (such as “D4On”) winds its way from the web browser via the magic of the Internet to the Photon, and then compared against the “if” statements in the function from line 73.
For example, when “D4On” is received, it is matched at line 101 by the Photon, which then turns on LED number 4 (for “Finished for today”), and also turns off the “DND” and “Working Alone” LEDs.
For all the other messages you can follow the code from line 73 to see how each button press on the webpage controls various combinations of LEDs and buzzer outputs. To save time there’s three custom buzzer functions that are used for differents audible alerts, so the message recipient can hear if the sender’s status has changed, or if they want a coffee or water. Pity the end user of this.
Finally, when you’ve entered the code in the Photon editor, click the little folder a the top-left of the screen which saves your code in the online storage provided by Particle:
Then you can upload the code to the Photon by clicking the lightning bolt. If there are no errors in the code, it will be compiled and shot off to the Photon. During this process, the LED on the Photon will blink slowly then quickly, then “breathe” on and off when it’s ready to go.
This could take up to a minute depending on your Internet connection. However if there’s something wrong, this will be shown in the bottom of the Photon editor page. Follow the messages to determine what’s wrong, then save and try again.
By now it should all be working. Now add labels next to the LEDs for the recipient to know what the sender is trying to say or demand, and you’re finished. A quick demonstration is shown in the following video:
So there you have it. On a broader sense, this can also be considered a demonstration of how to easily control things from a distance using a Particle Photon and a web-enabled device.
I hope you enjoyed making this or at least reading about it. If you find this sort of thing interesting, please consider ordering one or both of my books from No Starch Press, or other book sellers:
You must be logged in to post a comment.