<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Arduino on Bald Engineer</title><link>https://www.baldengineer.com/category/tutorials/arduino</link><description>Recent content in Arduino on Bald Engineer</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Wed, 10 Oct 2018 04:35:40 +0000</lastBuildDate><atom:link href="https://www.baldengineer.com/category/tutorials/arduino/index.xml" rel="self" type="application/rss+xml"/><item><title>Arduino millis() plus addition does not add up</title><link>https://www.baldengineer.com/arduino-millis-plus-addition-does-not-add-up.html</link><pubDate>Wed, 10 Oct 2018 13:00:23 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=7571</guid><description>In the past, I’ve covered how to reset Arduino millis() and have provided a growing list of examples using millis(). While reviewing the code for the elegoo Penguin Bot, I was reminded of a millis() mistake I see often: addition. The only way to properly handle millis() rollover is with subtraction. Let’s look at why (and how.)&#10;What is Arduino millis() The Arduino library has a function called millis() which returns the number of milliseconds the processor has been running. On other platforms, you might see references to a “tick counter.” It is the same idea. A hardware timer keeps incrementing a counter at a known rate. In this case, that rate is milliseconds.<p><img src="https://www.baldengineer.com/wp-content/uploads/2018/10/Arduino-millis-banner.jpg" alt="Arduino millis() plus addition does not add up"/></p></description></item><item><title>Arduino MKR Vidor 4000 Hands-On</title><link>https://www.baldengineer.com/arduino-mkr-vidor-4000-hands-on.html</link><pubDate>Wed, 15 Aug 2018 13:27:52 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=7510</guid><description>Earlier this week, I looked at the Arduino MKR Vidor 4000 during an AddOhms live stream. My goal was to understand the Vidor better. It is the new FPGA-based Arduino which started shipping this month. It runs about $60. You can learn more at the Vidor Product Page on the Arduino website.&#10;In this post, I briefly touch on the difference between an FPGA and a microcontroller. Then I walk you around the MKR Vidor 4000’s board. Using one of the examples, I talk a bit about how the various chips communicate with each other. This section also highlights what makes the Arduino FPGA board different from other development boards. Lastly, I answer “should you buy an Arduino MKR Vidor 4000?”<p><img src="https://www.baldengineer.com/wp-content/uploads/2018/08/Arduino-MKR-Vidor-4000-Blue-Background-1960.jpg" alt="Arduino MKR Vidor 4000 Hands-On"/></p></description></item><item><title>Standalone Arduino Turn-On and Debug</title><link>https://www.baldengineer.com/standalone-arduino-turn-on-and-debug.html</link><pubDate>Mon, 09 Jul 2018 13:00:54 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?post_type=video&amp;p=7489</guid><description>This AddOhms episode is part 3 of the “design your own Arduino” series. In this one I populate a bare PCB, reflow solder it, debug a few issues, and load the Uno bootloader. Originally, I designed 2 versions of the board. One version contained an error that I planned to fix in the episode. Well, turns out, the “correct” board had two issues which were more interesting.&#10;Check out the #27 show notes for links to a bunch of stuff in the episode, including the design files.<p><a href="https://www.youtube.com/watch?v=QYZY1anoUnA"><img src="https://i.ytimg.com/vi/QYZY1anoUnA/hqdefault.jpg" alt="Standalone Arduino Turn-On and Debug"/></a></p><p><iframe src="https://www.youtube-nocookie.com/embed/QYZY1anoUnA" title="Standalone Arduino Turn-On and Debug" width="560" height="315" loading="lazy" allowfullscreen="allowfullscreen"><a href="https://www.youtube.com/watch?v=QYZY1anoUnA">Watch this video on YouTube</a></iframe></p></description></item><item><title>Five Arduino math fixes for when it is wrong</title><link>https://www.baldengineer.com/arduino-math-fixes.html</link><pubDate>Wed, 04 Jul 2018 13:16:52 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=7463</guid><description>While the Arduino library does an excellent job of hiding some of C/C++’s warts, at the end of the day, it is still just C/C++. This fact causes a few non-intuitive issues for inexperienced programmers. When it looks like Arduino math is wrong, it is probably one of these reasons.&#10;When people ask me for help with their programming, I check each of these Arduino math mistakes. If your code seems to be hitting a bug, check to make sure it is not how the compiler handles math.<p><img src="https://www.baldengineer.com/wp-content/uploads/2018/07/Arduino-Math-Chalkboard-1960px-v2.jpg" alt="Five Arduino math fixes for when it is wrong"/></p></description></item><item><title>Arduino EEPROM stores any datatype</title><link>https://www.baldengineer.com/arduino-eeprom-stores-any-datatype.html</link><pubDate>Wed, 20 Jun 2018 13:00:46 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=7381</guid><description>Funny how a simple idea can spider out into multiple paths. Arduino EEPROM seemed like a straightforward concept. A few a years ago it was as easy as having either 512 or 1024 bytes of flash memory. The Arduino IDE offered an EEPROM library which let you read and write a single byte. Today, however, with many different processor architectures saving data to EEPROM varies. It is now possible to save any datatype to EEPROM but not on all boards and not all using the same method.<p><img src="https://www.baldengineer.com/wp-content/uploads/2018/06/Arduino-EEPROM-Hero-1600px.jpg" alt="Arduino EEPROM stores any datatype"/></p></description></item><item><title>Learn Six Oscilloscope Measurements with an Arduino DUT</title><link>https://www.baldengineer.com/six-oscilloscope-measurements-using-arduino.html</link><pubDate>Wed, 13 Jun 2018 18:44:22 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=7334</guid><description>One of the best ways to learn how to use a new piece of test equipment is to use it. Sounds easy, right? The problem is, sometimes when you are in the middle of troubleshooting your circuit, figuring out what the knobs on your scope do is an immense frustration. Use these 6 oscilloscope measurements, and just an Arduino Uno, to learn how to use a new or unfamiliar digital scope.<p><img src="https://www.baldengineer.com/wp-content/uploads/2018/06/Oscilloscope-Measurements-with-RTM3004-Alternative.jpg" alt="Learn Six Oscilloscope Measurements with an Arduino DUT"/></p></description></item><item><title>DIY Arduino PCB Pryamiduino (Video)</title><link>https://www.baldengineer.com/diy-arduino-pcb-pryamiduino.html</link><pubDate>Wed, 28 Feb 2018 14:00:03 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=7043</guid><description>Continuing the DIY Arduino tutorial series, this AddOhms episode shows how to create a PCB in KiCad. I make a joke that the original design was a rectangle, which I found boring and pointless. So instead, I designed a triangle to give the board 3 points. Get it? Puns! I am calling it the Pryamiduino. To be honest, I found not having a constraint to be a problem. By forcing a specific board size and shape, many decisions were more manageable.<p><img src="https://www.baldengineer.com/wp-content/uploads/2018/02/24-YouTube-Thumbnail-Template-v1-1920px.jpg" alt="DIY Arduino PCB Pryamiduino (Video)"/></p></description></item><item><title>Hologram.io connects Adafruit FONA</title><link>https://www.baldengineer.com/hologram-io-connects-fona-mqtt.html</link><pubDate>Thu, 08 Feb 2018 03:00:18 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6899</guid><description>While the buzzword “IoT “is relatively new, there has been a long time “internet of things” in operation. Those devices are called the far less sexy term “M2M” or machine-to-machine. These devices, around since the 90s, contain a microprocessor, some sensors, sometimes electromechanical hardware, and a cellular radio. These M2M devices were (and still are!) the early “Internet of Things.” Thanks to Hologram.io, you can join this new/old trend for free.<p><img src="https://www.baldengineer.com/wp-content/uploads/2018/02/adafruint-fona-hologram-mqtt-banner-1600px.jpg" alt="Hologram.io connects Adafruit FONA"/></p></description></item><item><title>DIY Arduino Schematic board and Checklist</title><link>https://www.baldengineer.com/diy-arduino-schematic-checklist.html</link><pubDate>Wed, 17 Jan 2018 14:00:18 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6915</guid><description>One of the last significant steps in a project is designing the custom PCB. This stage means creating a DIY Arduino board that is custom to the application. Two examples of my past projects are BinBoo, a Binary Clock, and Open Vapors, my reflow oven controller.&#10;While working on a project for a friend, I got to thinking; it would be nice to have a checklist for circuit elements to include on a DIY Arduino board. In the early days, I forgot to add a filter cap to AREF, for example.<p><img src="https://www.baldengineer.com/wp-content/uploads/2018/01/DIY-Arduino-Schematic-800px.jpg" alt="DIY Arduino Schematic board and Checklist"/></p></description></item><item><title>7 Arduino LCD display tips and tricks</title><link>https://www.baldengineer.com/arduino-lcd-display-tips.html</link><pubDate>Thu, 21 Dec 2017 17:30:03 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6860</guid><description>When I started working on Open Vapors, I thought the stumbling point would be the PID algorithm or safe AC line control. However, it turned out; I spent a significant amount of time understanding how to print to the Arduino LCD display correctly.&#10;If you need an easy to use RGB LCD, check out the Grove LCD from SeeedStudio. They sent me one to check out. The LCD comes with Seeed’s “grove connector system” which can connect to a variety of their Arduino-compatible boards. You can also pick up the Grove Base Shield which adds a variety of Grove connectors to an Arduino Uno. The Grove LCD makes it super easy to connect up a character LCD. It is very plug-and-play.<p><img src="https://www.baldengineer.com/wp-content/uploads/2017/12/Arduino-LCD-display.png" alt="7 Arduino LCD display tips and tricks"/></p></description></item><item><title>Arduino Keyboard Matrix Code and Hardware Tutorial</title><link>https://www.baldengineer.com/arduino-keyboard-matrix-tutorial.html</link><pubDate>Fri, 15 Dec 2017 14:00:26 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6830</guid><description>As a kid, I got the book " Upgrading and Repairing PCs." (Now in its 22nd edition.) It was the first book to explain to me the PC architecture. I considered, how were there so few pins on an AT-style keyboard connector when there were 101 keys on the keyboard? That is when I first learned about the keyboard matrix.&#10;Intel_P8049_AH_controller&#10;The keyboard matrix itself did not amaze me, but instead the idea there was an entirely separate 8-bit microcontroller inside of the keyboard. Early keyboards may have used the P8049AH, which, there is still some stock available to purchase. I was fascinated with the idea an entire computer was necessary to run the keyboard, to use my “real” computer. Why did it take something as complicated as a microcontroller?<p><img src="https://www.baldengineer.com/wp-content/uploads/2017/12/keyboard-matrix-tutorial.png" alt="Arduino Keyboard Matrix Code and Hardware Tutorial"/></p></description></item><item><title>PWM a 3-pin PC fan with an Arduino</title><link>https://www.baldengineer.com/pwm-3-pin-pc-fan-arduino.html</link><pubDate>Wed, 05 Jul 2017 13:13:53 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6577</guid><description>A question came up on IRC regarding how to PWM a 3-pin PC fan with an Arduino using analogWrite(). Controlling the fan was seemingly straightforward. The problem was that the hall effect sensor, or TACH signal, was incredibly noisy. The noise made it impossible to measure the fan’s rotation. Working through the question, I found three issues to tackle:&#10;You need to use a PNP transistor Filter capacitors help Create a non-blocking RPM measurement (with millis()) This post addresses all three issues regarding how to PWM a 3-pin PC fan with an Arduino.<p><img src="https://www.baldengineer.com/wp-content/uploads/2017/07/arduino-pc-fan-tutorial.png" alt="PWM a 3-pin PC fan with an Arduino"/></p></description></item><item><title>Soft Power Controller State Machine</title><link>https://www.baldengineer.com/software-power-controller-state-machine.html</link><pubDate>Wed, 21 Jun 2017 13:00:43 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6516</guid><description>Previously I looked at the hardware needed to build a Raspberry Pi soft power supply. This week I’m looking the state machine for the microcontroller. Why is such a complicated circuit necessary? I am replacing a Super Famicom (SNES) motherboard with the Pi. The trick is, I want to use the original power switch to turn the Pi on and off.&#10;This requirement presents a problem. When the switch goes into the “OFF” position, power needs to stay on long enough for the Pi to properly shutdown. So the switch itself can’t provide power to the Pi directly. With minor changes, the code in this state machine could be made to work with push buttons as well. If I add that feature in the future, I’ll update the code on the RPSPC GitHub project.<p><img src="https://www.baldengineer.com/wp-content/uploads/2017/06/soft-power-controller-state-diagram.jpg" alt="Soft Power Controller State Machine"/></p></description></item><item><title>Detect short and long button press using millis</title><link>https://www.baldengineer.com/detect-short-long-button-press.html</link><pubDate>Wed, 19 Apr 2017 12:00:48 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6440</guid><description>To detect a short and long button press using millis can give your project more functionality without adding more buttons. In this line-by-line example, I show how to react to a user pressing a button for a short period (100ms) or a long period (over 500ms). My example changes the blink rate of an LED on short presses. A long button press turns off the LED.&#10;In the code, I make use of a struct so that a single variable can be used to track multiple parameters. The benefit of this method is that adding multiple buttons is easy. You could create an array of these tyepdef’d variables.<p><img src="https://www.baldengineer.com/wp-content/uploads/2017/04/lbl-short-and-long-button-press.jpg" alt="Detect short and long button press using millis"/></p></description></item><item><title>Arduino Data Logger: Serial Monitor Alternatives</title><link>https://www.baldengineer.com/arduino-data-logger-options.html</link><pubDate>Wed, 05 Apr 2017 13:00:56 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6396</guid><description>The Arduino serial monitor is usable when you want to watch data from an Arduino. However, it does not have a built-in method for saving the data. Here are some ideas if you want to build an Arduino data logger with or without a PC.&#10;Important note on Arduino Data Logger examples With all of these examples, please remember that whenever you open the Arduino’s serial port, the board will reset. So if your log file shows “Initializing SD card…” with a few data lines in between, it is because there is a reset happening.<p><img src="https://www.baldengineer.com/wp-content/uploads/2017/04/arduino-data-logger-options-banner-v2b.jpg" alt="Arduino Data Logger: Serial Monitor Alternatives"/></p></description></item><item><title>Sending simple serial commands to an Arduino</title><link>https://www.baldengineer.com/simple-serial-commands-arduino.html</link><pubDate>Wed, 01 Mar 2017 15:00:16 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6376</guid><description>Sending simple serial commands to an Arduino is the easiest way to communicate between an Arduino and a computer. The computer could be a PC, a Raspberry Pi, or any device that communicates with serial.&#10;By sending and “decoding” a single character it is easy to add a simple debug menu or even serial menu. Plus, it is easy to extend.&#10;Single Character vs. Full Words The mistake I see many people make is that they try to send full-text strings as serial commands. For example, to turn on a LED, I have seen (silly) commands like “RED LED ON” or “RED LED OFF.” While you could use something like strcmp(), as I showed on the Multiple MQTT Topics example, that tends to be overkill for most serial commands.<p><img src="https://www.baldengineer.com/wp-content/uploads/2017/03/sending-simple-serial-commands-arduino-banner.jpg" alt="Sending simple serial commands to an Arduino"/></p></description></item><item><title>Multiple MQTT Topics with Arduino PubSubClient</title><link>https://www.baldengineer.com/multiple-mqtt-topics-pubsubclient.html</link><pubDate>Wed, 01 Feb 2017 13:00:22 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6348</guid><description>In my Arduino MQTT Examples, I kept things simple by only subscribing to a single topic. One of the strengths of MQTT is that a device can subscribe (or publish) to multiple topics. The broker will sort things out. Even though my first example only showed one, it is straight forward to get the Arduino PubSubClient library to subscribe to Multiple MQTT topics.&#10;The quick answer is that you need to look at the MQTT response to find out which topic sent the payload.<p><img src="https://www.baldengineer.com/wp-content/uploads/2017/02/multiple-mqtt-topics-banner-760px.jpg" alt="Multiple MQTT Topics with Arduino PubSubClient"/></p></description></item><item><title>Fading LED: analogWrite millis() Example</title><link>https://www.baldengineer.com/fading-led-analogwrite-millis-example.html</link><pubDate>Wed, 23 Nov 2016 14:34:21 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6250</guid><description>It’s a well-known fact of engineering: LEDs make everything look better. And that means a Fading LED is even better. Using Arduino’s analogWrite(), fading a LED is just a matter of a loop. If you use delay(), you can’t easily add other actions. What can you do? Well, Fading a LED with millis() is pretty simple. Here’s the code to do it and a quick explanation.&#10;//pwm-fade-with-millis.ino // Example Fading LED with analogWrite and millis() // See baldengineer.com/fading-led-analogwrite-millis-example.html for more information // Created by James Lewis const byte pwmLED = 5; // define directions for LED fade #define UP 0 #define DOWN 1 // constants for min and max PWM const int minPWM = 0; const int maxPWM = 255; // State Variable for Fade Direction byte fadeDirection = UP; // Global Fade Value // but be bigger than byte and signed, for rollover int fadeValue = 0; // How smooth to fade? byte fadeIncrement = 5; // millis() timing Variable, just for fading unsigned long previousFadeMillis; // How fast to increment? int fadeInterval = 50; void setup() { // put pwmLED into known state (off) analogWrite(pwmLED, fadeValue); } void doTheFade(unsigned long thisMillis) { // is it time to update yet? // if not, nothing happens if (thisMillis - previousFadeMillis &gt;= fadeInterval) { // yup, it's time! if (fadeDirection == UP) { fadeValue = fadeValue + fadeIncrement; if (fadeValue &gt;= maxPWM) { // At max, limit and change direction fadeValue = maxPWM; fadeDirection = DOWN; } } else { //if we aren't going up, we're going down fadeValue = fadeValue - fadeIncrement; if (fadeValue &lt;= minPWM) { // At min, limit and change direction fadeValue = minPWM; fadeDirection = UP; } } // Only need to update when it changes analogWrite(pwmLED, fadeValue); // reset millis for the next iteration (fade timer only) previousFadeMillis = thisMillis; } } void loop() { // get the current time, for this time around loop // all millis() timer checks will use this time stamp unsigned long currentMillis = millis(); doTheFade(currentMillis); } Global Variables for Fading LED Constants The constant “pwmLED” is the pin that gets faded. (Make that pin supports analogWrite().) The two #define statements, UP and DOWN, are simple states for the LED. They make the code easier to read. The “maxPWM” value is set to 255 for 8-bit AVR boards like the Uno. If you’re using the ESP8266, set this value to 1023. (You can also use the constant “PWMRANGE.”)<p><img src="https://www.baldengineer.com/wp-content/uploads/2016/11/led-fading-millis-example.jpg" alt="Fading LED: analogWrite millis() Example"/></p></description></item><item><title>Measure PWM Current with a Modified Moving Average</title><link>https://www.baldengineer.com/measure-pwm-current.html</link><pubDate>Wed, 28 Sep 2016 13:00:16 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6217</guid><description>Pulse Width Modulation (PWM) makes it possible to dim lights, control the speed of motors, and (with the help of filters) generate analog reference voltages. When measuring the voltage or current of a PWM signal, there are unique challenges. You can use this tutorial to measure PWM current with a modified moving average (MMA).&#10;As I’ve mentioned in a few posts, I’m working on an RGB LED IoT controller. Soon I’ll post some detailed information on that. In the meantime, one choice I made was to include an INA219 current sensor on the LED power supply. For prototyping, I’m using the Adafruit Breakout Board, but my final design uses the same parts integrated into a custom PCB.<p><img src="https://www.baldengineer.com/wp-content/uploads/2016/09/measure-pwm-current-with-mma.jpg" alt="Measure PWM Current with a Modified Moving Average"/></p></description></item><item><title>5 Common Arduino Programming Mistakes</title><link>https://www.baldengineer.com/5-common-arduino-programming-mistakes.html</link><pubDate>Wed, 17 Aug 2016 13:39:41 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6145</guid><description>Whenever someone sends me some code that doesn’t work, there are a few common Arduino programming mistakes that I check. Some of these mistakes I make myself. In most cases my code will compile just fine. Sometimes, these mistakes won’t generate any compiler error.&#10;When my Arduino code is acting up, these are the first things I check. Here are my 5 common Arduino programming mistakes, I use to debug non-working code.<p><img src="https://www.baldengineer.com/wp-content/uploads/2016/08/5-common-arduino-programming-mistakes.jpg" alt="5 Common Arduino Programming Mistakes"/></p></description></item><item><title>Arduino Bootloader, What is it?</title><link>https://www.baldengineer.com/arduino-bootloader.html</link><pubDate>Wed, 15 Jun 2016 13:00:14 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6066</guid><description>Almost all microcontroller (and microprocessor) development systems use some form of a bootloader. Often called firmware, mistakenly, the Arduino bootloader is one example. Since it is a rather popular platform, let’s use it as an example. Let’s talk about what a bootloader does and how it works.&#10;When a microcontroller turns on, it only knows how to do one thing. Typically, that one thing is to run an instruction found at a specific memory location. Often this location address 0x0000, but not always. Usually, this memory location will contain a jump instruction to another place in memory, which is the start of the user program. The bootloader, however, exists in a slightly separate memory space from the user program.<p><img src="https://www.baldengineer.com/wp-content/uploads/2016/06/arduino-bootloader-banner.jpg" alt="Arduino Bootloader, What is it?"/></p></description></item><item><title>MQTT Tutorial for Raspberry Pi, Arduino, and ESP8266</title><link>https://www.baldengineer.com/mqtt-tutorial.html</link><pubDate>Wed, 24 Feb 2016 16:00:45 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5799</guid><description>This week’s MQTT Tutorial connects a Raspberry Pi, ESP8266 (or Arduino), and a PC together. Remember last week’s post provided an overview of message brokers and MQTT. We learned that MQTT is a hub and spoke protocol for sending messages between IoT devices. Clients can subscribe or publish messages to a central server, called a broker.&#10;Now it’s time to connect our IoT devices together!&#10;For this MQTT tutorial, I have three main elements:&#10;• My Computer, which will act as the broker.&#10;• Raspberry Pi running Python&#10;• ESP8266 controlling an LED<p><img src="https://www.baldengineer.com/wp-content/uploads/2016/02/mqtt-tutorial-banner.jpg" alt="MQTT Tutorial for Raspberry Pi, Arduino, and ESP8266"/></p></description></item><item><title>MQTT Introduction and Tutorial Part One</title><link>https://www.baldengineer.com/mqtt-introduction.html</link><pubDate>Wed, 17 Feb 2016 16:00:25 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5778</guid><description>MQTT is an easy way for Internet of Things (IoT) devices to communicate with each other. This light-weight protocol can be used with a simple 8-bit Arduino to a Raspberry Pi to a multi-core PC to Amazon Web Services. It is that versatile.&#10;This MQTT Tutorial is broken into two parts. Part one is an MQTT Introduction. You’ll understand how publish/subscribe message brokering works. Next week, Part two will be a tutorial on using MQTT to communicate between a PC, Raspberry Pi, and ESP8266.<p><img src="https://www.baldengineer.com/wp-content/uploads/2016/02/mqtt-tutorial-banner-mqtt-part-one.jpg" alt="MQTT Introduction and Tutorial Part One"/></p></description></item><item><title>Use Arduino millis() with buttons to delay events</title><link>https://www.baldengineer.com/use-millis-with-buttons-to-delay-events.html</link><pubDate>Wed, 27 Jan 2016 16:00:16 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5720</guid><description>One of the common questions related to using the millis() function in Arduino, is around timed events. After an event occurs, you want the code to wait for some time before doing the next step. But you don’t want to stop the program with delay().&#10;In this example, we will use millis() to wait a few seconds after a pushbutton press to turn on an LED. Then a few seconds later, we will turn it off. All without using delay().<p><img src="https://www.baldengineer.com/wp-content/uploads/2016/01/lbl-delayedMillisActions.png" alt="Use Arduino millis() with buttons to delay events"/></p></description></item><item><title>Difference between Programming and Native Ports</title><link>https://www.baldengineer.com/difference-between-programming-and-native-ports.html</link><pubDate>Wed, 11 Nov 2015 16:00:04 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5570</guid><description>When you hear the name “Arduino,” does a picture of the Uno come to mind? While the most popular, this 8-bit based board isn’t the only Arduino available today. There are some other boards available like the Due and recently introduced Zero, which are far more advanced than the humble Uno.&#10;These are 32-bit microcontroller boards that have a very different architecture compared to the relatively straightforward Uno. In fact, one of the most striking differences is that the Due and Zero have two USB ports.<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/11/due-ports_banner.png" alt="Difference between Programming and Native Ports"/></p></description></item><item><title>Proper Larson Scanner with Software PWM (Repost)</title><link>https://www.baldengineer.com/proper-larson-scanner-with-sw-pwm.html</link><pubDate>Wed, 21 Oct 2015 16:00:03 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5501</guid><description>Last week I had a detailed Arduino tutorial on software pulse width modulation using millis() and micros(). Why? Because I wanted to create a Proper Larson Scanner, with persistence and at least 8 LEDs.&#10;KITT larson scanner example&#10;Even though it is a popular project for the Arduino Uno, most Larson scanner tutorials, like my first one, have a few flaws. First, there is no persistence, or tail, to the LED as it moves back and forth. Persistence could be solved by using pulse-width-modulation. The Uno and other 328p-based micros only have 6 Pulse Width Modulation (PWM) pins. And let’s be honest, every project is made better by adding more LEDs. :)<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/10/cylon-pumpkin-proper-larson-banner.jpg" alt="Proper Larson Scanner with Software PWM (Repost)"/></p></description></item><item><title>Arduino Software PWM with millis()</title><link>https://www.baldengineer.com/software-pwm-with-millis.html</link><pubDate>Wed, 07 Oct 2015 13:00:04 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5478</guid><description>The Arduino Uno has six pins dedicated to Pulse Width Modulation (PWM). PWM is great for analog-like control for the speed of motors or LED fading. But what if you want to control more than 6 devices? Or what if you’re using the PWM pins to control servo motors, but still want to fade an LED on a 7th pin?&#10;One option is to change boards and processors. For example, you could move up to the Arduino Mega 2560. That means a bigger board and more cost.<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/10/lbl-arduino-software-pwm.jpg" alt="Arduino Software PWM with millis()"/></p></description></item><item><title>How Arduino digitalWrite Works – and why AVR is Faster</title><link>https://www.baldengineer.com/how-arduino-digitalwrite-works-and-why-avr-is-faster.html</link><pubDate>Mon, 05 Oct 2015 13:00:18 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?post_type=link&amp;p=5450</guid><description>Previously I looked at the speed difference between digitalWrite and direct port manipulation. It was a chance to check out a Saleae Logic Analyzer. Andrew at !Crash-Bang Prototyping took the analysis a step further. He broke down what is going on inside of digitalWrite().&#10;This study is useful. When you’re ready to move beyond the Arduino IDE or the core functions, you can decide if you need your own version of digitalWrite().</description></item><item><title>AddOhms #15: Pull-Up Resistors (and buttons)</title><link>https://www.baldengineer.com/addohms-15-pull-up-resistors-and-buttons.html</link><pubDate>Mon, 10 Aug 2015 13:00:05 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?post_type=video&amp;p=5293</guid><description>The latest AddOhms looks at why you need a pull-up resistor when using push-buttons. This video goes into what happens when you leave a pin floating, what a floating pin means, and how the pull-up works. You can get more information about the video on the AddOhms Episode page.&#10;Pull-Up Resistors can be a difficult topic to understand. That’s why I made this video.&#10;This tutorial is the 2nd time I’ve made a video on pull-ups. Despite being a single resistor, it can be a difficult topic for new hardware designers to understand. The pull-up video was the first video tutorial I ever made. In fact, the YouTube version uses YouTube’s “stabilization” algorithm, which gives the video a very warped feel.<p><a href="https://www.youtube.com/watch?v=wxjerCHCEMg"><img src="https://i.ytimg.com/vi/wxjerCHCEMg/hqdefault.jpg" alt="AddOhms #15: Pull-Up Resistors (and buttons)"/></a></p><p><iframe src="https://www.youtube-nocookie.com/embed/wxjerCHCEMg" title="AddOhms #15: Pull-Up Resistors (and buttons)" width="560" height="315" loading="lazy" allowfullscreen="allowfullscreen"><a href="https://www.youtube.com/watch?v=wxjerCHCEMg">Watch this video on YouTube</a></iframe></p></description></item><item><title>Blink without delay() explained line-by-line</title><link>https://www.baldengineer.com/blink-without-delay-explained.html</link><pubDate>Wed, 05 Aug 2015 13:00:27 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5275</guid><description>Making the move to millis()-based code can be daunting. You have to rethink your logic, implement flags, program a state machine — and more importantly, start using millis(). Generally in forums and on IRC people will just point to the “blink without delay” example, hoping the commented code is enough for a new user. It’s not enough.&#10;I have a growing list of millis()-based tasks posted in my millis() cookbook. But sometimes that those examples might be too simple or not close enough to your project’s end target. That got me thinking about different ways to help explain how millis() works. I thought “wow, you need to understand every line of an example” which leads me to: line-by-line.<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/08/lbl-blinkWithoutDelay.png" alt="Blink without delay() explained line-by-line"/></p></description></item><item><title>Microcontroller state machine with enum tutorial</title><link>https://www.baldengineer.com/state-machine-with-enum-tutorial.html</link><pubDate>Wed, 29 Jul 2015 13:00:07 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5251</guid><description>Flag variables are great, and totally not evil, when you just have two states: ON or OFF. What about when you have multiple states? Is there an option better than creating multiple flag variables?&#10;The C-language has a declaration type just for this purpose. It is called an enumeration, or enum.&#10;Setting up a state machine with enum is a surprisingly simple. Arduino and embedded programmers should use them!&#10;All you need to do is create descriptive tag names, and let the compiler assign them an integer value. Unlike a #define which is just a macro replacement, the compiler treats an enum as your personal variable type.<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/07/state-machines-with-enum-tutorial.jpg" alt="Microcontroller state machine with enum tutorial"/></p></description></item><item><title>Benchmarking Arduino's digitalWrite() with a Logic Analyzer</title><link>https://www.baldengineer.com/digitalwrite-on-a-logic-analyzer.html</link><pubDate>Wed, 22 Jul 2015 13:00:55 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5228</guid><description>Recently I picked up a device called Logic from Saleae. It’s a 4-channel USB-based logic analyzer. While learning how the simple, but effective, UI works I ran some timing benchmarks on my Arduino Uno. The subject? digitalWrite(). I wanted to know how fastdigitalWrite() could turn on two (or more) pins.&#10;Almost all Arduino users start out with the simple “blink” sketch. Turn pin 13 ON, delay, turn it OFF, and delay again. The heart of this version of “Hello World!” is the digitalWrite() function. Many Arduino users never even think about all of the stuff this single function call hides.<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/07/saleae-logic-analyzer-and-arduino-uno.jpg" alt="Benchmarking Arduino&amp;#39;s digitalWrite() with a Logic Analyzer"/></p></description></item><item><title>Flag variables are not evil (for Microcontrollers)</title><link>https://www.baldengineer.com/flag-variables-are-not-evil-for-microcontrollers.html</link><pubDate>Wed, 15 Jul 2015 13:00:13 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5206</guid><description>Getting programming questions answered on the internet can be problematic. Programmers love to have opinions, stick to those ideas, and express them to you even when their opinion has nothing to do with your question(s).&#10;Not only am I going to explain how to use flag variables in your code, I am going to encourage their use—which most programmers avoid.&#10;However, this advice comes with two caveats.&#10;This information only applies to limited resource environments like an Arduino, LaunchPad or PIC. Use flag variables very carefully when you do use them. The following flag variable usage examples are Arduino-centric but apply to any microcontroller platform, including the Energia project for TI Launchpads.&gt; Flag variables are a Good Thing(tm) – when used properly<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/07/fun-with-flag-variables.png" alt="Flag variables are not evil (for Microcontrollers)"/></p></description></item><item><title>Which Arduino Starter Kit is the Best?</title><link>https://www.baldengineer.com/which-arduino-starter-kit-is-the-best.html</link><pubDate>Wed, 01 Jul 2015 13:00:33 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5136</guid><description>The other day my friend called me up. He told me how much he missed building circuits and wanted to start again with the Arduino.&#10;So he asked me “which Arduino starter kit is the best to buy?” At which point, I drew a long breath. Easy question, not always an easy answer.&#10;Picking out an electronics kit depends on a number of factors. You should consider:&#10;Your budget What you already have What you want to do #1 and #2 are probably pretty easy to figure out. For many beginners, it’s “not much” and “nothing.” When you don’t know #3, what you want to do, then it gets trickier. Coming back to my friend, what did I do? Well, I went out and bought each one of the kits in this post. I put myself in his shoes and maybe these are your shoes as well.<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/07/which-kit-is-best.jpg" alt="Which Arduino Starter Kit is the Best?"/></p></description></item><item><title>Pushbutton and Flashing LED tutorial with millis()</title><link>https://www.baldengineer.com/pushbutton-and-flashing-led-tutorial-with-millis.html</link><pubDate>Wed, 06 May 2015 14:00:21 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=4930</guid><description>How to blink (or flash) a LED without delay() and detect button pushes One of the limitations of the delay() function is that nothing else can really be done. This presents a problem when you want to flash a LED while waiting for a pushbutton to be pressed.&#10;Flashing the LED with millis() and using a flag variable to find if the LED should be flashing solves this problem.&#10;Consider this another example to my virtual millis() cookbook.<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/05/pushbutton-and-millis_bb-fixed2.png" alt="Pushbutton and Flashing LED tutorial with millis()"/></p></description></item><item><title>Arduino pinMode on Analog Inputs</title><link>https://www.baldengineer.com/arduino-pinmode-on-analog-inputs.html</link><pubDate>Mon, 20 Apr 2015 14:00:50 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?post_type=tip&amp;p=4869</guid><description>All Arduino boards contain analog and digital pins. The Arduino functions have different calls depending on the pin type. For example, when calling analogRead(), an analog input pin is automatically changed from a digital input (or output) into an analog input. For this reason, it isn’t necessary to call the pinMode function on the pin. However, when I write Arduino Sketches, I still put a pinMode(A0, INPUT) in setup anyway.</description></item><item><title>Case Study in Optimization: Faster SPI on AVRs</title><link>https://www.baldengineer.com/case-study-in-optimization-faster-spi-on-avrs.html</link><pubDate>Mon, 30 Mar 2015 13:03:48 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?post_type=link&amp;p=4781</guid><description>The Arduino Library provides functions like shiftOut() and digitalWrite(). These functions are simple and effective, but they are slow. Of course, they’re doing a lot more than just toggling bits. Faster isn’t always necessary and can sometimes lead to more difficult debugging. And as Donald Knuth said,&#10;…premature optimization is the root of all evil.&#10;So what happens, when you do need to optimize? For example, if shiftOut() is too slow for your project, what do you do? In Ralph’s post, Fastest AVR software SPI in the West, he breaks down different SPI code implementations into their assembly code.</description></item><item><title>Check-out these seven new features in the Arduino 1.6 release</title><link>https://www.baldengineer.com/seven-new-features-in-arduino-1-6-release.html</link><pubDate>Wed, 25 Mar 2015 16:15:00 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=4461</guid><description>The (official) Arduino team has finally released the 1.6 version of the Arduino software. After being in the making for over 2 years, this release is an exciting one!&#10;1.6 marks the end of split releases between the traditional 8-bit boards and ARM based boards. There’s some really cool features built-in, so keep reading to see my take on the good, the bad, and the ugly.<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/03/arduino-1-6-1-glossy.png" alt="Check-out these seven new features in the Arduino 1.6 release"/></p></description></item><item><title>Installing Arduino Library from GitHub</title><link>https://www.baldengineer.com/installing-arduino-library-from-github.html</link><pubDate>Wed, 07 Jan 2015 14:45:58 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=3195</guid><description>What happens when you have a random chip or sensor you want to interface with an Arduino, but don’t know how? You search for a pre-existing library of course. And where are many libraries hosted and available from? A place where eager developers hack together code, post updates, and collaborate with others: Github!&#10;tldr; If you’re having trouble installing a library, look directly at Step 3. Installing a library Many Arduino libraries are available from GitHub. It really fosters the spirit of Open Source work. If you come across a library you need on GitHub, getting it into the Arduino IDE is relatively simple. However, if you’re new to GitHub (or the Arduino IDE) you might miss the simple steps.<p><img src="https://www.baldengineer.com/wp-content/uploads/2015/01/github-library-banner.png" alt="Installing Arduino Library from GitHub"/></p></description></item><item><title>Well formatted Arduino code in one click</title><link>https://www.baldengineer.com/one-click-clean-arduino-code.html</link><pubDate>Fri, 16 May 2014 15:00:06 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2416</guid><description>Warning, the title of this post is a little bit misleading. It isn’t just one-click to get cleanly formatted code, it’s actually two.&#10;There are two things seasoned programmers will tell new programmers, that they don’t understand (at first):&#10;Always comment your code Properly indent code The problem? As a new programmer, you might not know how to do #2 until you get some experience.&#10;How indenting helps The reason you indent code is to make it easier for a reader to understand the code’s flow. A compiler (well except in Python) doesn’t care if two lines line up or not. T he recent issues around Apple’s “goto fail;” are a great example of how indentation is meaningless to a C compiler.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/autoformat-banner.png" alt="Well formatted Arduino code in one click"/></p></description></item><item><title>Teach your Arduino to listen with µSpeech</title><link>https://www.baldengineer.com/teach-your-arduino-to-listen-with.html</link><pubDate>Tue, 08 Apr 2014 15:00:11 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2299</guid><description>When most people say “Arduino” they mean an ATmega328 based board like the Uno. This means a simple 8-bit microcontroller with only 2K of RAM. That’s 2,048 bytes of memory to work with. So when someone asked me if the Arduino could do speech recognition, to be honest, I laughed. Then my jaw dropped when I saw µSpeech. A speech recognition library for the Arduino Uno’s ATmega328.&#10;The algorithm used is sophisticated and results will vary based on the types of words used as well as the hardware. It uses only 160 bytes of RAM.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/uSpeech-Banner.png" alt="Teach your Arduino to listen with µSpeech"/></p></description></item><item><title>Arduino: Assignments != Comparisons</title><link>https://www.baldengineer.com/arduino-assignments-do-not-equal-comparisons.html</link><pubDate>Thu, 03 Apr 2014 15:00:59 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2321</guid><description>There is one mistake that all C programmers make, regardless of experience. You’ll do it often when you get started, but never completely stop. The mistake? Confusing the “assignment” operator with the “comparison” operator. Take a look at this line of code:&#10;if (something = 0) { Notice the problem? If not, then you might fall into this common trap. The most annoying part? A C-Compiler won’t give an error. That code is legal C. Legal code doesn’t mean you’ll get the results you expect. In fact, this is probably not even close to what you wanted. This simple mistake and why it “works” is explained below.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/assignment-comparison-banner.png" alt="Arduino:  Assignments != Comparisons"/></p></description></item><item><title>When do you use the Arduino's Serial.flush()?</title><link>https://www.baldengineer.com/when-do-you-use-the-arduinos-to-use-serial-flush.html</link><pubDate>Thu, 02 Jan 2014 12:00:47 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2061</guid><description>In the Arduino library, the Serial object has a method called “flush().” Often users go throwing it into programs without fully understanding what it does. It doesn’t help that it’s functionality changed when version 1.0 of the Arduino IDE was released.&#10;Does Serial.flush() affect the Transmit Buffer or the Receive Buffer and when do you need to use it?&#10;What does Serial.flush() do? From the Arduino reference for Serial.flush (found on this page):<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/when_to_use_flush_banner.png" alt="When do you use the Arduino&amp;#39;s Serial.flush()?"/></p></description></item><item><title>5 Myths Everyone Believes about Arduino (that aren't true)</title><link>https://www.baldengineer.com/5-arduino-myths.html</link><pubDate>Wed, 01 Jan 2014 12:00:59 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2232</guid><description>Having spent the past 6 years writing code for the Arduino platform, I’ve noticed a trend in myths from both newcomers and veteran users. Here are the Top 5 Myths I see come up on forums, in classes, and on IRC.&#10;1. The Arduino uses its own Language This myth isn’t helped by the Arduino.cc home page used to say&#10;“T he microcontroller on the board is programmed using the Arduino programming language.”<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/arduino_myths_banner.png" alt="5 Myths Everyone Believes about Arduino (that aren&amp;#39;t true)"/></p></description></item><item><title>AddOhms #7 - Comparing Arduino and Raspberry Pi</title><link>https://www.baldengineer.com/addohms-7-comparing-arduino-and-raspberry-pi.html</link><pubDate>Mon, 16 Dec 2013 12:00:59 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2127</guid><description>The seventh AddOhms TutorialCast has gone “live”. (Gone “uploaded” sounds wrong.) Being able to understand difference between an Arduino and a Pi is a critical point for many new electronics hobbyist. The boards seem so similar, but they are so different. AddOhms #7: Comparing the Arduino and Raspberry Pi&#10;Full Episode Notes are available on the Episode’s homepage.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/addohms-ep7-banner.png" alt="AddOhms #7 - Comparing Arduino and Raspberry Pi"/></p></description></item><item><title>Arduino: De-Bounce a Button with micros() or millis()</title><link>https://www.baldengineer.com/arduino-de-bounce-a-button-with-micros.html</link><pubDate>Fri, 13 Dec 2013 12:25:45 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2095</guid><description>The Arduino is fast, humans are slow. When you push down a button, what seems like a single change to slow humans is really multiple presses to an Arduino. This is known as “bouncing.” Figure 1 is an oscilloscope screenshot showing what could happen when a button is pressed.&#10;Figure 1 - All the bouncing!&#10;The top trace shows the high-low-high transition of the button press. But notice all of the activity at the start of the high-to-low transition. The bottom trace is a “zoomed-in” view of that area. The button is actually transitioning multiple times before staying low. Internally the contacts are “bouncing.” This could result in false reads. In software, we can ignore these bounces by waiting some period of time after the first transition.<p><img src="https://www.baldengineer.com/wp-content/uploads/2013/12/MG_1763.jpg" alt="Arduino:  De-Bounce a Button with micros() or millis()"/></p></description></item><item><title>Arduino: Chasing LEDs with millis()</title><link>https://www.baldengineer.com/arduino-chasing-leds-with-millis.html</link><pubDate>Thu, 12 Dec 2013 12:00:34 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2117</guid><description>A popular LED project is the “Larson Scanner.” This scanner emulates the effect seen on KIT from Knight Rider and the Cylons in Battlestar Galactica. The code is usually written using “delay()” which means you can’t combine it with anything else. The following code could be put into a function, called periodically and allow your code to scan while doing other things.&#10;One thing to note, a proper Larson Scanner has some persistence to the next and previous LEDs, this code does not. Maybe that would be a good exercise for the reader?<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/millis-chasing-led-larson-scanner-banner.png" alt="Arduino:  Chasing LEDs with millis()"/></p></description></item><item><title>Arduino: Timing Code with Millis() as a Stopwatch</title><link>https://www.baldengineer.com/arduino-timing-code-with-millis-as-a-stopwatch.html</link><pubDate>Wed, 11 Dec 2013 12:25:22 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2085</guid><description>Since most Arduino boards do not have debug capability, this limits the programmer to using Serial.prints. A useful piece of information might be knowing how long certain parts of code are running. Here’s a simple example that demonstrations:&#10;How to properly use Serial.flush() (hint: it’s for TRANSMIT, not RECEIVE!) How long Serial.print()s can “tie up” the Arduino. At 9600 baud, you’ll see that the Arduino is only busy for about 20 milliseconds in the first chunk of code, but busy for 93 milliseconds in the next. That’s because the Arduino (since 1.0) started using a transmit-buffer. Did you know your code doesn’t wait for a Serial.print to finish?<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/millis-code-stopwatch-banner3.png" alt="Arduino:  Timing Code with Millis() as a Stopwatch"/></p></description></item><item><title>Arduino: Independent On-Off Times with Millis()</title><link>https://www.baldengineer.com/millis-ind-on-off-times.html</link><pubDate>Tue, 10 Dec 2013 12:25:29 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2059</guid><description>When using delay() to flash a LED there is a time for the LED to be on and then off. This makes it easy to have independent control of the “on” and “off” times. The standard blink without delay example doesn’t give you this flexibility.&#10;millis-cookbook-two-duty-cycles&#10;This example code gives you complete independent control of how long a LED (or any OUTPUT pin) stays “ON” or “OFF”. This also demonstrates a very simple two-state state machine.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/millis-ind-on-off-banner.png" alt="Arduino:  Independent On-Off Times with Millis()"/></p></description></item><item><title>Arduino Millis() Examples</title><link>https://www.baldengineer.com/arduino-millis-examples.html</link><pubDate>Mon, 09 Dec 2013 23:00:51 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?page_id=2055</guid><description>You’ve recently learned about millis() and can’t way to delete all of your references to delay(). The problem is that you don’t know quite how to convert your code into millis()-compatible code. Here is a (running) list of millis() examples I’ve put together to help.&#10;Baldengineer’s Arduino millis() Examples Arduino Multitasking - Step by step examples of how to convert delay() code into millis() based code, to simulate multitasking. Police Lights - Flash two LEDs like strobing police lights Control ON and OFF time for a flashing LED. - More control than “blink without delay” Stopwatch Example - Calculate how much time code takes to execute Chasing LEDs - Larson-scanner style chasing pattern De-bounch a button (or switch) - No need for de-bouncing capacitor Delayed events after a button push - Timed events (button push is just example.) analogWrite() PWM Fading - No delay() and a simple function to keep a LED fading with PWM Detect Short and Long Button Press - Give one button multiple functions You might also want to check out my “Blink Without Delay - Line by Line Tutorial.” It is a much more in-depth explanation than the comments provided with the Arduino IDE example.</description></item><item><title>The hidden Arduino Macro F() fixes random lock ups</title><link>https://www.baldengineer.com/arduino-f-macro.html</link><pubDate>Wed, 20 Nov 2013 12:25:33 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=1995</guid><description>It’s 3am but you are not going to bed until you squash this last bug. You sprinkle Serial.print() statements everywhere you can think of, and then that’s when all hell breaks loose: Your code randomly locks up, the LEDs go crazy, and you’ve had it. What’s going on? You’ve run out of RAM!&#10;All of those Serial.print() statements are composed of c-style strings. Which are “constant character arrays.” In order for those arrays to work properly, they get loaded into the ATmega’s RAM before your code starts running. Which can be a problem because 2,048 bytes of RAM doesn’t allow for much.</description></item><item><title>Three Alternatives to Arduino's Serial Monitor</title><link>https://www.baldengineer.com/alternatives-to-arduinos-serial-monitor.html</link><pubDate>Tue, 19 Nov 2013 11:39:29 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=1839</guid><description>The Arduino IDE includes a “Serial Monitor” which is decent for basic serial communication. However, when you need real time serial interaction or data logging capabilities, that’s when one of these serial monitor alternatives can come in handy.&#10;putty [Windows] Download: PuTTY. License: MIT.&#10;Hands-down one of my favorite terminal applications for Windows is PuTTY from Simon Tatham. In addition to being a great serial terminal it can also handle telnet, ssh, and a host of other things (no pun intended). The source is available and looks like it runs on UNIX platforms, but I have never tried. If you’re using Windows, this is probably your best go-to terminal application. Every Windows machine I use gets PuTTY in the Start Menu shortcuts.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/serial-alt-banner.png" alt="Three Alternatives to Arduino&amp;#39;s Serial Monitor"/></p></description></item><item><title>Const vs #define - When do you use them and why?</title><link>https://www.baldengineer.com/const-vs-define-when-do-you-them-and-why.html</link><pubDate>Thu, 14 Nov 2013 11:13:40 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=1944</guid><description>Arduino boards have microcontrollers with notoriously small amounts of RAM. The Uno only has 2,048 bytes of static RAM available for your program to store variables. So when you need to keep non-changing variables out of RAM which is best to use const or #define?&#10;What is #define #define is often misunderstood because it isn’t a programming statement. Instead, it sets up a macro which causes a text replace to occur before code is compiled. For example in this code:</description></item><item><title>Arduino pinMode(): When to use and why</title><link>https://www.baldengineer.com/when-to-use-arduinos-pinmode-and-why.html</link><pubDate>Mon, 11 Nov 2013 11:57:39 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=1923</guid><description>All Arduino boards have GPIO pins with digital and analog capabilities. The Arduino pinMode() function determines how the pins will operate. A surprise might be that in some cases it is not necessary to use it. And when you do, pinMode() may not always work the way you expect. This post outlines how the Arduino pinMode() function works and when you should (or not should) use it.&#10;pinMode(13, OUTPUT); Arduino pinMode() scope This post focuses on the 8-bit AVR Arduino boards such as the Uno, Mega, and Leonardo. The processors on these boards are the ATmega328, ATmega2560, and ATmega32u4, in that order. For the most part, this information does apply to non-AVR and 32-bit Arduino variants. When in doubt, double check with the Arduino Reference pages for details to specific platforms.</description></item><item><title>Ouch. The Arduino GSM shield has a pretty serious design flaw, with its capacitors.</title><link>https://www.baldengineer.com/ouch-the-arduino-gsm-shield-has-a-pretty-serious-design-flaw-with-its-capacitors.html</link><pubDate>Sat, 14 Sep 2013 02:44:39 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=1867</guid><description>Tantalum is a really misunderstood capacitor. Well, all capacitors are misunderstood, but that’s a subject for another post. I ran across this post on the Arduino forums on the Arduino GSM shield. In the post, ddewaele, reports that the shield blew up, catching fire. At first some might think it was due to abuse by the user. While it is possible that reversing the polarity or applying over-voltage could cause a catastrophic failure, it is also possible that the user doing nothing wrong could result in the same failure mode!<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/tantalum-gsm-post2.png" alt="Ouch. The Arduino GSM shield has a pretty serious design flaw, with its capacitors."/></p></description></item><item><title>Sawtooth waveform with the Arduino Due's Built-In DAC</title><link>https://www.baldengineer.com/sawtooth-waveform-with-the-arduino-dues-built-in-dac.html</link><pubDate>Fri, 08 Feb 2013 00:36:18 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=1533</guid><description>Users of the ATmega328 based Arduino boards will recognize that the analogWrite() function doesn’t actually do anything analog. It just sets the duty cycle of a pulse width modulated (PWM) signal. The (new) Arduino Due board, which I have had limited time to play with, actually sports two Analog DAC channels. Using a very simple for() loop, it is possible to generate a sawtooth waveform using these channels.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/sawtooth-banner.png" alt="Sawtooth waveform with the Arduino Due&amp;#39;s Built-In DAC"/></p></description></item><item><title>How to Fix: Arduino is damaged and can't be opened</title><link>https://www.baldengineer.com/how-to-fix-arduino-is-damaged-and-cant-be-opened.html</link><pubDate>Fri, 23 Nov 2012 03:06:52 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=1394</guid><description>Open source software that isn’t signed by an identified developer can cause headaches upgrading it on OSX. While working with the Arduino Due the first time, I downloaded 1.5 Beta of the Arduino IDE and ran into this error:&#10;“Arduino is damaged and can’t be opened. You should move it to the Trash.&#10;Here’s why you see the “… is damaged and can’t be opened” dialog and how to fix it.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/gatekeeper-banner.png" alt="How to Fix:  Arduino is damaged and can&amp;#39;t be opened"/></p></description></item><item><title>Arduino: Fixing "Serial Port in Use"</title><link>https://www.baldengineer.com/arduino-fixing-serial-port-in-use.html</link><pubDate>Mon, 08 Oct 2012 09:46:16 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=1207</guid><description>Here’s a couple of quick tips to get around the Arduino IDE error message “Serial Port in Use.” These mostly apply to OSX, but since it is UNIX based, they may make sense for Linux as well.&#10;List Open Files Applies to: OSX, Linux.&#10;The check to see if another process (like a previous run of avrdude) is holding the serial port open is easy on both Linux and OSX. Just open a terminal and run the command: lsof. The command will report back all files that are currently open by the operating system. UNIX-based operating systems do everything through files, so this command is useful to see what is keeping a serial device open. Since lsof gives a list of everything that’s open, and there are a lot of “files”, use grep to only list what is relevant.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/Arduino-Serial-Port-in-Use-Banner.png" alt="Arduino:  Fixing &amp;#34;Serial Port in Use&amp;#34;"/></p></description></item><item><title>Arduino: Getting Real Time Help</title><link>https://www.baldengineer.com/arduino-getting-real-time-help.html</link><pubDate>Mon, 13 Aug 2012 09:30:08 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=1155</guid><description>Note: The IRC Channel (along with all of Freenode) got nuked.&#10;While the Arduino Project Team provides their official Arduino forums, sometimes real-time help is just a bit better. When that is the case, I encourage you to visit the freenode.net IRC channel, #arduino. While as of today it is not an official channel, there are a number of great people available to help.&#10;You can find me under the nick “baldengineer”, big surprise, I know. Others like kline, Yoston and pwillard are also excellent people to ping with questions.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/Screen-Shot-2012-08-12-at-9.03.39-PM.png" alt="Arduino:  Getting Real Time Help"/></p></description></item><item><title>Arduino: Sending and Receiving Multi-Digit Integers</title><link>https://www.baldengineer.com/arduino-multi-digit-integers.html</link><pubDate>Mon, 30 Jul 2012 09:18:32 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=1105</guid><description>When Serial data is transmitted to an Arduino, it is sent one byte at a time. Even though you might type “123” in the Serial Monitor, that’s not quite what is sent. Instead the bytes “1” then “2” then “3” are sent. Once received into a buffer on the Arduino, these individual bytes need to be reassembled into something useful. The Arduino IDE provides Serial.readBytes() as one option. However, if you aren’t sure how many digits you are going to receive, this may not work. So another option is to use Serial.readBytesUntil() like so:<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/07/Serial-Monitor-123.png" alt="Arduino:  Sending and Receiving Multi-Digit Integers"/></p></description></item><item><title>Arduino Example: Police Lights with millis()</title><link>https://www.baldengineer.com/arduino-example-police-lights-with-millis.html</link><pubDate>Sat, 28 Jul 2012 18:00:20 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?page_id=1121</guid><description>Based on a question from Andrew on the initial Multitasking with millis() tutorial, this example shows how to create a Police-Light like strobe effect. The following code uses no calls to delay().&#10;Code also available via Pastebin.org.&#10;// English for which LED to Strobe #define RED 0x0 #define BLUE 0x1 // Variable to track which LED is on byte whichLED = RED; // Where are the LEDs connected? const int LED_Red = 7; const int LED_Blue = 11; // State variables for the LEDs byte Red_State = LOW; byte Blue_State = LOW; // Some delay values to change flashing behavior unsigned long switchDelay = 250; unsigned long strobeDelay = 50; // Seed the initial wait for the strobe effect unsigned long strobeWait = strobeDelay; // Variable to see when we should swtich LEDs unsigned long waitUntilSwitch = switchDelay; // seed initial wait void setup() { pinMode(LED_Red, OUTPUT); pinMode(LED_Blue, OUTPUT); } void loop() { digitalWrite(LED_Red, Red_State); // each iteration of loop() will set the IO pins, digitalWrite(LED_Blue, Blue_State); // even if they don't change, that's okay // Toggle back and forth between the two LEDs if ((millis() - waitUntilSwitch) &gt;= 0) { // time is up! Red_State = LOW; Blue_State = LOW; whichLED = !whichLED; // toggle LED to strobe waitUntilSwitch += switchDelay; } // Create the stobing effect if ((millis() - strobeWait) &gt;=0 ) { if (whichLED == RED) Red_State = !Red_State; if (whichLED == BLUE) Blue_State = !Blue_State; strobeWait += strobeDelay; } } State Variables Red_State and Blue_State Instead of using digitalWrite() directly, “state” variables are used to determine the state (on or off) of each LED. This allows logic inside the loop() to determine when the lights should be turned on or off. Each iteration of loop() will update the LEDs with a digitalWrite() based on this state variable.</description></item><item><title>Arduino: Toggling Outputs</title><link>https://www.baldengineer.com/arduino-toggling-outputs.html</link><pubDate>Mon, 23 Jul 2012 09:00:13 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=1072</guid><description>Did you know it is possible to toggle the state of a Arduino OUTPUT pin using a single line of code? It’s true! It’s also possible to use digitalRead() on an OUTPUT pin. Assuming pin 13 was set to output, this single line of code will cause the LED to change state (or flash) each time it is called:&#10;digitalWrite(13, !digitalRead(13)); Keep reading to understand how these two tricks work.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/07/picasion.com_59157f597d88f4db5519afff49288894.gif" alt="Arduino:  Toggling Outputs"/></p></description></item><item><title>Arduino: How do you reset millis() ?</title><link>https://www.baldengineer.com/arduino-how-do-you-reset-millis.html</link><pubDate>Mon, 16 Jul 2012 14:00:42 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=861</guid><description>The quick answer to “How do you reset millis()” is: You Don’t! And here’s why: if you did, it would potentially break most libraries and functions that rely on it. Generally the reason people want to reset it, is that they are concerned about rollover. Instead of focusing on resetting millis(), here is how to use it correctly.&#10;Need to brush up on how millis() works? I’ve got a tutorial on how to effectively multi-task with millis() and another line-by-line tutorial on blink Without delay Avoiding rollover and checking how much time as passed is done in a single line:<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/07/stopwatch_000018042439.jpg" alt="Arduino:  How do you reset millis() ?"/></p></description></item><item><title>Arduino Comparison Chart</title><link>https://www.baldengineer.com/arduino-comparison-chart.html</link><pubDate>Sat, 07 Jan 2012 05:30:45 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?page_id=730</guid><description>When getting started with the Arduino, the shear number of board options can be intimidating. While the variety is a great option, it can be daunting to a new user. Many people are afraid of selecting the wrong board, or their budget doesn’t allow for buying multiple boards. Just looking at the “official” boards listed on the Arduino.cc site, there are 14+ different Arduino board types to consider. Then there are a variety of 3rd-party boards with their own uniqueness.</description></item><item><title>Arduino Internal Pull-Up Resistor Tutorial</title><link>https://www.baldengineer.com/arduino-internal-pull-up-resistor-tutorial.html</link><pubDate>Fri, 30 Dec 2011 07:31:32 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?page_id=704</guid><description>When hooking up switches or buttons to an Arduino I/O pin, sometimes the results might appear completely random. Sometimes it will appear as though there is a delay from when the button is pressed until the state of the pin actually changes. Other times the pin’s value will seem to randomly fluctuate from HIGH to LOW. Even more maddening might be as your finger gets closer to the switch, the pin’s state changes! The fix to these problems is simple: use the Arduino Internal Pull-up Resistor. Here’s how they can fix this problem and how you can use them with an Arduino board.<p><img src="https://www.baldengineer.com/wp-content/uploads/2011/12/youtube-jJnD6LdGmUo.jpg" alt="Arduino Internal Pull-Up Resistor Tutorial"/></p></description></item><item><title>Spotting Arduino Clones</title><link>https://www.baldengineer.com/spotting-arduino-clones.html</link><pubDate>Mon, 26 Dec 2011 23:40:20 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=600</guid><description>Open Source Hardware (OSH) means not only releasing devices, but all of the documentation associated with them. For some projects, this may include the actual CAD files used to produce the device. For example, the Arduino team produces not only schematics but the Eagle PCB CAD files for each of their boards. The great thing about such disclosure is that one can easily tweak the existing design for their own purposes. The downside is that nearly anyone can submit the exact same files to their own production house and have immediate clones.<p><img src="https://www.baldengineer.com/wp-content/uploads/2011/12/6578137169_07cab589d0.jpg" alt="Spotting Arduino Clones"/></p></description></item><item><title>Video Tutorial: Buttons and Pull-Ups</title><link>https://www.baldengineer.com/video-tutorial-buttons-and-pull-ups.html</link><pubDate>Mon, 19 Dec 2011 05:20:26 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=565</guid><description>This is a 4-minute video version of the Arduino Pull-Up Tutorial:</description></item><item><title>Arduino UNO SMD Amnesia</title><link>https://www.baldengineer.com/arduino-uno-smd-amnesia.html</link><pubDate>Thu, 20 Jan 2011 16:10:22 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=353</guid><description>On the Janurary 15, 2011 edition of Adafruit’s “Ask An Engineer” live video chat, I heard LadyAda mention something about “Arduino Amnesia.” After investing the situation a little further, it turns out there are some Issues with the new Arduino UNO Smd edition.&#10;A bug in the new bootloader can be triggered on power-cycle causing the SMD version of the board to not load the previously stored sketch. The good news is there is already a fix for the bug. Either return the board to your Official Distributor or use a ISP to program the new bootloader.<p><img src="https://www.baldengineer.com/wp-content/uploads/2011/01/MRI_head_side1.png" alt="Arduino UNO SMD Amnesia"/></p></description></item><item><title>millis() Tutorial: Arduino Multitasking</title><link>https://www.baldengineer.com/millis-tutorial.html</link><pubDate>Fri, 07 Jan 2011 04:01:55 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=294</guid><description>After working through these exercises, check out this article on how to avoid rollover or reset mills(). After learning how to flash a single LED on your Arduino, you are probably looking for a way to make cool patterns, but feel limited by the use of delay(). If you ask in the forums, you get told to look at the “Blink Without Delay” example. This example introduces the idea of replacing delay() with a state machine. If you’re confused how to use it, this tutorial is setup to take you from blinking two LEDs with delay, to using an alternate method, right down to how you can use millis().<p><img src="https://www.baldengineer.com/wp-content/uploads/2011/01/eca9168a883497e1bb33bd3a47ba1baa-300x197.png" alt="millis() Tutorial: Arduino Multitasking"/></p></description></item></channel></rss>