Modding my Rowing Machine with an Arduino – Part 1 – Arduino Basics
Tags: arduino, embedded, iot, beginners
Published: 2019-05-21 16:44:58

---
title: Modding my Rowing Machine with an Arduino – Part 1 – Arduino Basics
published: true
tags: arduino,embedded,IoT,beginners
canonical_url: https://alistairevans.co.uk/2019/05/11/modding-my-rowing-machine-with-an-arduino-part-1-arduino-basics/
---

I’ve got a rowing machine in my garage that I use pretty regularly, and it displays some statistics on a basic little read-out, including speed, calories burnt, number of ‘strokes’ and so on.

![](https://alistairevans.files.wordpress.com/2019/05/20190511_120716.jpg?w=333&h=333)<figcaption>The rowing machine read-out.</figcaption>

My mission is to replace the simple LED read-out with my own board that will capture the sensor data it uses, upload it somewhere and then do some fun stuff with that data.

For background, I have a little past experience in embedded programming, but I haven’t used it in years. I understand the basics of GPIO pins and similar, but I place myself firmly in the ‘beginner’ category with embedded development.

I hadn’t touched an Arduino before today, when I started writing this post, so this is going to cover just getting to grips with Arduino basics, and subsequent updates will go through all the steps needed to mod my rowing machine!

## Picking an Arduino Board

My only real criteria for picking an Arduino board is that I can connect the sensors on my rowing machine, and also that I can connect to WiFi to get data off it.

![](https://alistairevans.files.wordpress.com/2019/05/20190511_120730.jpg?w=262&h=262)<figcaption>The back of the rowing machine display.</figcaption>

From the connections on my rowing machine, I can tell I need two connections on the board that can read analog sensor values, so I knew I would need two ADCs (Analog to Digital Converters) on my board, one for the speed and one for the counter.

Going through the Arduino website to figure out which board I wanted (turns out there’s a lot of choice), I picked the [Arduino Uno Wifi Rev2](https://store.arduino.cc/arduino-uno-wiFi-rev2), which:

- Has 2 ADCs (for reading the sensors on my rowing machine).
- A built-in WiFi module for connectivity (so I can upload my data).
- A pretty attractive price of about £35 (as of writing in May 2019) plus shipping.

Shipping only took a couple of days, and once it arrived I was ready to go. You will also need a USB Type B cable. You can pick one up off Amazon for about £5, but I had an old one lying around.

![](https://alistairevans.files.wordpress.com/2019/05/20190511_115822-collage.jpg?w=424&h=424)

## Setup

After plugging in the Arduino board with the USB connector, I went to the [getting started guide](https://www.arduino.cc/en/Guide/ArduinoUnoWiFiRev2) for my particular board (the site has different pages for each one).

> I believe that a lot of the following content should work for most Arduino boards that don’t have WiFi, but I am not certain.

From there I tried out both the web-based and desktop IDE Arduino provide, but I decided I want to work in a familiar environment. Luckily, it turns out that trusty [VS Code](https://code.visualstudio.com/)can come to my rescue, because it has an extension for working with Arduino, with the added bonus of having decent intellisense.

You will need to download the regular Arduino desktop IDE from [here](https://www.arduino.cc/en/guide/windows) before you can use VS Code with your Arduino; the extension needs to use the tools it supplies.

Go ahead and install the VS Code Arduino extension (by Microsoft), then go and configure the extension if you need to set the installation path for your Arduino installation to the non-default setting.

![](https://alistairevans.files.wordpress.com/2019/05/image-7.png?w=698&h=379)

## What is an Arduino Program?

What actually is an Arduino Program anyway, and how is it different from a console application on my desktop?

Basically, all Arduino ‘programs’ run C++ code you write. Each program fundamentally consists of a **setup** and a **loop**.

{% gist https://gist.github.com/alistairjevans/da7b8d22cb514717d91560e323f429dd %}

You can sort of think of setup as your ‘main’ method, but you exit it immediately and start looping.

One thing that you need to remember with an embedded program is that your program **never stops** ; it runs until the device doesn’t have power, you reset the board, or you upload a new program. There is no ‘exit’.

In an Arduino program you can do a lot of the things you’d expect from a C++ program, like having additional C++ code files (files with a .cpp extension work just fine). You do have a lot less memory to play with though; the processor on my Arduino only has 6KB of RAM. As someone who tends to work on web applications that consume hundreds of MB, it’s a bit jarring, but 6KB is actually plenty for my needs.

When you want to run your program, you compile it as you would with a normal program; the Arduino components on your desktop then upload the program to the device (over the USB connection) and store it in Flash memory. Again, you can’t have massive applications; my board has 48KB of Flash to fit the program in.

## My First Arduino Program

First off, I’m going to make an LED flash. Big stuff, I know. My Arduino (and most of them I think), have a built-in LED that you can turn on and off from your program.

Let’s make a new project in VS Code. Create a new folder somewhere and open it in VS Code.

Then, to start a new ‘project’, run Arduino: Initialize from the command palette. This created a blank app.ino file and let me select my board, which got me started.

I found that I got an intellisense error in the created ino file:

![](https://alistairevans.files.wordpress.com/2019/05/image-1.png?w=1100)

Clicking on the ‘fix-it’ bulb took me to the C++ include path settings:

![](https://alistairevans.files.wordpress.com/2019/05/image-2.png?w=1100)

After a quick search of the Arduino install directory for ‘pgmspace.h’, turned out I was missing an additional include path:

_C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include_\*\*

After I added that to the list with the necessary extra backslashes, closed and then re-opened my app.ino file, no more squiggles, and I get nice intellisense.

#### Controlling an LED

My built-in LED is on PIN #13 of the processor (I used the [Arduino Board reference](https://www.arduino.cc/en/reference/board) to check what was available); in your program there is an LED\_BUILTIN constant already supplied that references it.

* * *

A bit of embedded basics here; everything you do in embedded programming is basically turning pins on and off on your processor.

![](https://alistairevans.files.wordpress.com/2019/05/image-6.png?w=296&h=296)<figcaption>The big arrow is pointing to a pin</figcaption>

Want to turn on an LED? Set the ‘level’ of the pin connected to the LED to HIGH (which means it has voltage on it). To turn it off, set the level to LOW (which means it has no/negligible voltage on it).

* * *

I had to configure the LED pin to be an output pin in my setup method, and then set it HIGH and LOW in my loop. Put some delays in there and you have a flickering LED!

{% gist https://gist.github.com/alistairjevans/704ea8221458e651814f6bce85a644d0 %}

You can upload the program from the command palette (or CTRL+ALT+U).

![](https://alistairevans.files.wordpress.com/2019/05/20190511_1046312_1.gif?w=313&h=313)<figcaption>GIF of an LED blinking (very exciting!)</figcaption>

You might encounter one or more problems getting that program downloaded (like I did):

**COM Port**

![](https://alistairevans.files.wordpress.com/2019/05/image-3.png?w=559&h=366)

I had problems getting the COM Port (the Arduino connects as a virtual COM Port over USB) to work first time, so my code wouldn’t upload. I had to go into the main Arduino IDE and install the package it recommended for my board. This installed different drivers, which changed the COM Port to Atmel rather than Microsoft.

I also had to go into Windows Device Manager, go into the settings, and change the COM Port to not be the default COM3. Only then would it actually upload.

**Select the Right Board!**

![](https://alistairevans.files.wordpress.com/2019/05/image-4.png?w=1100)

Pro Tip – make sure you pick the right board in the VSCode footer, and select the processor.

Mine is the Arduino Uno WiFI Rev2, with the A4809 processor.

![](https://alistairevans.files.wordpress.com/2019/05/image-5.png?w=364&h=220)

## Hello World

Next step, I want to do the tried and tested programming exercise of writing Hello World to the ‘Console’.

The Arduino doesn’t have a console to write to in the normal sense you might be familiar with; what it can do however is write to the Serial connection you use to upload your programs, and the Arduino extension in VS Code can display it.

* * *

More embedded basics; Remember how I said that everything in embedded programming is turning pins on (HIGH) and off (LOW)? Well, that’s true of writing text to a Serial connection too, but we do it extremely quickly.

Luckily, we don’t have to do all the pin changes ourselves (phew); there are functions already supplied by the Arduino libraries that will do this for us.

When we configure our Serial port, we need to set its ‘baud’, or speed. This tells the Serial code how fast we want to send characters. 9600 baud means that we are sending approximately 9600 bytes/characters per second. Whatever is ‘listening’ on the other end needs to know the speed, otherwise you’ll just get junk out.

* * *

{% gist https://gist.github.com/alistairjevans/96023f041265a8d461cdcf838b615e29 %}

So once we’ve setup our Serial Port, in our loop, once per second we print our Hello World to the Serial port.

Once you’ve copied that code into your app.ino, upload the program as you would normally.

Once you’ve uploaded your program, it’s initially a bit anti-climatic, nothing is obviously happening. To see the output, we need to open the Serial Monitor. Click on the little connection logo in the VS Code footer:

![](https://alistairevans.files.wordpress.com/2019/05/image-8.png?w=1100)

This will bring up the Serial Monitor. At this point, you will probably just be getting nonsense, so you will want to change the ‘baud’ for the Serial Monitor to 9600.

![](https://alistairevans.files.wordpress.com/2019/05/image-9.png?w=1100)

Once you’ve done that, you should get your Hello World being displayed!

![](https://alistairevans.files.wordpress.com/2019/05/helloworld.gif?w=1100)

## Next Steps

Ok, so that’s it for now. Subsequent posts will cover:

- Wiring up my sensors and reading analogue values.
- Using the WiFi module to sent HTTP requests
- Using the data I collect!