Running I2C on Pro Micro (1) - Setting up Pro Micro
Announcement: A book that extensively revises and summarizes the content of this article is now available. Please check it out if you want comprehensive information.
In DIY keyboards and sensor modules, it's common to use I2C to connect and process multiple ICs. In this series, we'll use the I2C port on the Pro Micro to operate an IO expander.
In this first article, we'll start by getting the Pro Micro to work on a breadboard. While I2C isn't involved yet, this is an important step for future use.
Note that we'll be implementing this on a breadboard for experimental purposes.
Components Needed
Here are the components needed for Part 1. If you want to buy everything at once, please refer to the other articles as well.
- Breadboard (BB-801 or similar) x1
- Half-size breadboard x1 (to be used in combination)
- Pro Micro + pin headers x1
- The Type-C version is less prone to breaking, so while expensive, it's more reliable. If you can secure it with a glue gun or have other Pro Micros to spare, those are fine too.
- As mentioned later, there are various types of Pro Micro, so be careful
- Reset switch x1
- Yushakobo's 2-pin tactile switch is cheap and convenient, but anything that can be inserted into a breadboard is fine.
- Jumper wires x many
- You'll want plenty as they're used for various purposes
- Cable to connect Pro Micro to PC
- Apparently, charge-only cables might not be recognized properly
Since we're just verifying operation, this is all we need.
Brief Terminology / Referenced Information
- Types of Pro Micro: There are many compatible versions. It's important to know which Pro Micro you have and understand its chip and pin assignments.
- This article is helpful: Pro Micro and Its Variations - zenn.dev
- Pro Micro pin configuration (pin assignment): Information about what each pin coming out of the Pro Micro does. You can check which leg of the chip (ATmega32U4) is connected where. This also varies by type, so look at the board's markings to find the same one. We'll proceed with the common one shown in the figure below
Quoted from: https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/ProMicro16MHzv1.pdf
Software to Prepare
- Arduino IDE
- An environment for burning firmware onto the Pro Micro. This is convenient
Implementation
1. Soldering Pro Micro and Pin Headers
To insert the Pro Micro into the breadboard, we need to attach pin headers.
You need to consider which side should face up, and whether the pin header height is sufficient (can you insert the cable?). I'm trying to secure it with the cable insertion port facing down to make it less prone to breaking. However, it's generally the opposite, and the circuit diagram will be horizontally flipped, so be careful.
Probably reversed
For soldering, you only need to do the pins we'll use for now. These are GND x3, RST, and VCC. As you use more pins, solder them as needed. From the next part onwards, we'll also use 2(SDA) and 3(SCL), so if you want to do it all at once, add these to your soldering.
2. Wiring on the Breadboard
Place the Pro Micro at the very top and wire the necessary pins. As shown in the figure below, connect the + and - lanes on the left and right of the breadboard, connect GND and VCC, and connect a switch between #RST (RST with an overline) and GND to complete. It's easier later if you leave more space on the side with the Pro Micro's pins 2 and 3.
Pro Micro and Reset Switch
As is common with Reset behavior, the #RST pin is high when nothing is done, and low when resetting. Therefore, we connect it to GND with a switch to trigger the reset process. This is described in the following Hookup Guide.
Pro Micro & Fio V3 Hookup Guide - SparkFun Learn - learn.sparkfun.com
By the way, #RST is internally pulled up, so it will be high if left alone. Internal pull-up is a useful feature that will appear frequently in the future.
Quoted from: Figure 8-1: https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7766-8-bit-AVR-ATmega16U4-32U4_Datasheet.pdf
3. Burning a Program with Arduino IDE
Launch Arduino IDE, copy and paste the sample code from the following link, and compile it. It's good because the LED blinks, making it easy to understand.
In Arduino IDE, you need to select which board you're targeting. You might despair thinking "There's no Pro Micro?", but as mentioned in the previously cited article, it's compatible with Arduino Leonardo, so select that. Apparently, it might not work well with some types, so refer to this article and try burning with a different board selection.
To burn, double-click (or single-click depending on the Pro Micro type) the reset switch, which will activate the bootloader for 750ms, during which you burn the program. If you press the upload button (Cmd+U) in Arduino IDE beforehand, it will automatically recognize and burn when the bootloader starts.
You also need to select the target (Port) for burning. If you've never burned a program before, it might not be recognized at all. The bootloader should be recognized, so reset and see if an item appears in the Port list. If found, quickly select it and have it burn.
If it doesn't work, first check if the bootloader is recognized. On Mac, type ls /dev/tty.*
without the Pro Micro connected. On a Macbook, you might see /dev/tty.Bluetooth-Incoming-Port
by default. On Windows, you might be able to see it from something like Device Manager (unverified). Next, connect it, double-click reset, and check if the display increases with the same command. In my case, it appeared as /dev/tty.usbmodem12101
(via USB hub). If it doesn't appear, the Pro Micro itself might be faulty, or the reset button might not be functioning properly. In the latter case, try shorting the Pro Micro's #RST and GND with tweezers (x2 times) to see if it starts.
4. Viewing Output in Arduino IDE
If you've successfully written the program and the Pro Micro starts blinking, you're almost there.
First, check if it appears in /dev/tty
or similar even when not in bootloader mode. This confirms that it's being correctly recognized by the PC in normal state. In the case of Arduino Leonardo, when you burn from the IDE, the USB firmware is burned together, allowing good communication with the PC. If it's not found, you might not have burned with the appropriate board selected. Looking at the aforementioned article, try Arduino Leonardo and others as well.
If it seems to be connected properly, open "Tools" -> "Serial Monitor", and if you can see a phrase like "Hello world!", you're good to go. There's a Serial.println(...)
statement in the program, which can be checked from Arduino IDE. In other words, you can do print debugging.
If you get a message saying it can't connect to the serial monitor, check if you've selected the wrong Port, and try unplugging and replugging to see what happens.
In this state, you should be able to update the program just by pressing the upload button without entering the bootloader. This is convenient.
Summary
The initial setup part is easy to get stuck on, so if you've made it this far successfully, it's cause for celebration. I also lost a day before realizing I needed to select the Arduino Leonardo board.
Next time, we'll get into the main topic of I2C.