Artemis Development with the Arduino IDE
Introduction
The SparkFun Artemis is an amazing module. So much functionality packed into a tiny 10x15mm footprint! But what really makes it powerful is the ability to quickly write sketches and build projects using only Arduino code. However, for more industry oriented programmer, it is also compatible with Arm® Mbed™ OS. Whether you are using one of our boards that has the Artemis module pre-integrated or have your own, this tutorial will get you started with the Arduino IDE and familiarize you with the various interfaces of the Artemis module.
Required Materials
To follow along with this tutorial, you'll need development board with an Artemis module and a USB-C cable.
Programming Firmware
Users interested in flashing their module will need an ARM Programmer and need to solder on a JTAG header. We recommend these programmers from our catalog:
Examples
Some of the Arduino examples in this tutorial will require additional hardware.
Suggested Reading
If you aren’t familiar with the following concepts, we recommend checking out these tutorials before continuing.
Installing an Arduino Library
What is an Arduino?
Installing Arduino IDE
Installing Board Definitions in the Arduino IDE
Serial Communication
Serial Peripheral Interface (SPI)
Analog vs. Digital
Processor Interrupts with Arduino
How to Solder: Through-Hole Soldering
How to Install CH340 Drivers
Designing with the SparkFun Artemis
Artemis Development with Arduino
Do I Need Drivers?
Some of our development boards utilize a WCH CH340C or CH340G UART-to-serial chip. A driver should not be required for Mac OSX, Linux, Windows 10; however, we do have a driver installation tutorial available for users.
How to Install CH340 Drivers
August 6, 2019
The rest of our development boards utilize an NXP interface chip with DAPLink. A driver is not required for Mac OSX, Linux, Windows 10; however, there is a serial port driver available for Windows 7 (only), which is provided by Mbed™. Further instructions and details on installing the serial port driver can be found in the Mbed™ OS documentation.
(*As the Mbed™ OS documentation is continually updated, so are the links. Therefore, users may find it useful to look under the Tutorials > Serial Communication section of the (updated) Mbed™ OS documentation for the serial port driver information.)
Setting up the Arduino IDE
Installing the Arduino IDE
Most users will be familiar with the Arduino IDE and it's use. As a point of reference for professional developers who aren't aware, the Arduino IDE is an open-source development environment, written in Java, that makes it easy to write code and upload it to a supported board. For more details, feel free to check out the Arduino website.
To get started with the Arduino IDE, check out the following tutorials:
Installing an Arduino Library
What is an Arduino?
Installing Arduino IDE
Installing Board Definitions in the Arduino IDE
Installing the Apollo3 Board Definitions
Users will need to install the SparkFun Apollo3 Boards board definitions in the Arduino IDE for our development boards with an Artemis module. Please use the guide below, to get started with installing the SparkFun Apollo3 core for the Artemis modules:
Installing Board Definitions in the Arduino IDE
September 9, 2020
Otherwise, users can check out this tutorial on Installing Additional Cores provided by Arduino. Users will also need the .json
file for the SparkFun Apollo3 Arduino Core:
Once, the .json
file has been added to the Additional Boards Manager URLs, search for Apollo3
in the Boards Manager.
To complete the installation process, selected the SparkFun Apollo3 Boards core and click on the INSTALL button that appears in the lower, right-hand corner. The board definition along with the associated libraries and example sketches will be installed automatically. (*Make sure that the Apollo3 Arduino core is at least version 2.0.0.)
SparkFun's Apollo3 boards and examples listed in the Arduino IDE. (Click to enlarge)
Installing the BLE Library
For users interested in the BLE functionality of the Apollo3 and Artemis boards, we have provided full support to the Arduino BLE library. Additional details about the library can be referenced from the documentation provided by Arduino.
Users will need to install the Arduino BLE library to take advantage of that functionality; please use the guide below, to get started with installing the Arduino BLE library:
Installing an Arduino Library
January 11, 2013
Programming the Artemis Module
Users should refer to the hookup guide for their board for the programming procedures. However, below is a summary of the available methods:
Drag and Drop Method
Development boards that utilize an NXP interface chip with DAPLink with appear as a mass storage device for drag-and-drop programming. The interface chip will accept a .hex
or .bin
file that is compiled for that specific board and program the Artemis module accordingly.
Serial Upload w/ ASB or SVL Bootloader
Known Issue: With the latest v2.0.0 Apollo3 Arduino core, there is an issue uploading sketched using the SVL.
Users can use the ASB to workaround this issue; however, it is recommended that users be aware of that there seems to be some sort of issue when uploading with the Serial Monitor left open. Even though the upload completes successfully the program does not execute.
Development boards that utilize a WCH CH340C or CH340E UART-to-serial chip will be programmed utilizing the serial bootloader.
The Artemis modules on these boards come preloaded with two bootloaders. The SparkFun Variable Bootloader (SVL) will allow you reliably and conveniently load new code at data rates up to 921600bps. In addition to the SVL, we also enable the Ambiq factory bootloader for secure boot applications. Almost all users should use the SparkFun Variable Bootloader and forget about the Ambiq factory bootloader. For more information checkout the programming section of the Designing with the Artemis Module tutorial. Don't worry - you cannot damage or brick your Artemis using the incorrect bootloader.
Status LED: Blink
The status LED is great for troubleshooting and debugging code. For all of our boards with an Artemis module, the status LED can be accessed in the Mbed-CLI with the variable LED1
. However, we have already linked the LED_BUILTIN
variable to the Blink example built into the Arduino IDE.
Blink
With full Arduino support, users will be able to implement the built-in examples of the Arduino IDE on the Artemis DK. To begin, let's start with the most basic example: Blink. From the drop down file menu, pull up the script:
Note: Users who need the compiled binary code in order to program the Artemis DK, save this example somewhere that is easily accessible; the desktop is a good option. (*Remember to use Save As, so that you retain the original example within the Arduino IDE.)
Blink example being saved to the Desktop.
Next, you will want to select the appropriate board from the tools drop down menu: Tools > Board: > Select a Board
The last step is to program your board. Use the programming method associated with your board.
Operation
This example is very fundamental and should result in the LED blinking on and then off, with a period of a second. Follow the steps for programming the associated board to see the code in action.
STAT
LED blinking. Serial Port: Hello World and Enabling Peripherals
In this example, we will create a code that outputs Hello World
to the serial monitor, through the USB connection of the associated board. Unfortunately, there isn't an example built into the Arduino IDE, so users will need to copy and past the code below.
language:c
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// print out "Hello World"
Serial.println("Hello World");
delay(500);
}
Follow the steps for programming the associated board to see the code in action.
Operation: Serial Monitor
This example outputs Hello World
to the serial monitor, through the USB connection of the associated board. Follow the steps for programming the associated board to see the code in action.
Once the board is programmed, open the serial monitor on the Arduino IDE; make sure to set the baud rate to 9600 baud. Hello World
should be printed out continuously.
Hello World
print out in the Arduino IDE Serial Monitor. Configuring Peripheral Serial Ports/Pins
In order for users to understand how to adapt their code to configure the peripheral UART ports and pins, we have provided a built-in example for the Apollo3 core. From the file drop-down menu: File > Examples > Apollo3 > Serial.
Serial
example for the Apollo3 core. ADC: AnalogRead
The ADC pins are useful for measuring analog voltage inputs. To get started, we have provided a built-in example for the Apollo3 core. From the file drop-down menu: File > Examples > Apollo3 > AnalogRead.
AnalogRead
example for the Apollo3 core. Wiring
Users should be familiar with the ADC example in the SIK. Please, remember that some boards are rated at 3.3V; and therefore, the potentiometer should be tied to 3.3V on the high side.
Operation: Serial Monitor
This example outputs ADC values to the serial monitor, through the USB connection of the associated board. Follow the steps for programming the associated board to see the code in action.
Once the board is programmed, open the serial monitor on the Arduino IDE; make sure to set the baud rate to 115200 baud. A 14-bit value should be printed out based on the associated ADC input voltage.
PWM: AnalogWrite
The PWM pins are useful for controlling servos or emulating an analog voltage functionality. To get started, we have provided a built-in example for the Apollo3 core. From the file drop-down menu: File > Examples > Apollo3 > AnalogWrite.
AnalogWrite
example for the Apollo3 core. (Click to enlarge) Operation
This example is very fundamental and should result in the LED dimming/fading on and off. Follow the steps for programming the associated board to see the code in action.
I2C: Qwiic OLED Display
The I2C pins are useful connecting to peripheral devices. In this example, let's use the Qwiic OLED Display and the example code from the online tutorial.
The hookup guide direct users through the installation of the associated Arduino libraries. Once the library is installed, follow the instructions from the online tutorial to get the example up and running.
Wiring
Users should be familiar with our Qwiic system. Here is a link to our Qwiic cable kit, if necessary.
Operation
This example display various patterns across the display. Follow the steps for programming the associated board to see the code in action.
Configuring Peripheral I2C Ports/Pins
In order for users to understand how to adapt their code to configure the peripheral I2C ports, we have provided the following example for the Apollo3 core: File > Examples > Apollo3 > I2C.
I2C
example for the Apollo3 core. (Click to enlarge) SPI: BME680 Environmental Sensor
The SPI pins are useful connecting to peripheral devices, with high-speed communication. In this example, let's use the SparkFun Environmental Sensor Breakout - BME680 and the SPIDemo example from the library provided for the product. Additional, materials like hookup wire and soldering equipment will be required.
Users will need to follow the hookup guide to install the associated Arduino libraries. Once the library is installed, select the SPIDemo example from the File > Examples > BME680 > SPIDemo menu. Refer to the board's hookup guide to verify the pins utilized for the SPI library; the example code may need to be adapted.
Wiring
Users will need to follow the hookup guide to connect the sensor properly. Soldering the appropriate SPI connections using some hookup wire.
Operation: Serial Monitor
This example outputs sensor values to the serial monitor, through the USB connection of the associated board. Follow the steps for programming the associated board to see the code in action.
Once the board is programmed, open the serial monitor on the Arduino IDE; make sure to set the baud rate to 9600 baud. The environmental sensor readings should be be displayed on the Serial Monitor.
Configuring Peripheral SPI Ports/Pins
In order for users to understand how to adapt their code to configure the peripheral SPI ports, we have provided the following example for the Apollo3 core: File > Examples > Apollo3 > SPI.
SPI
example for the Apollo3 core. (Click to enlarge) Bluetooth: LED
Install BLE Library
For users interested in the BLE functionality of the Apollo3 and Artemis boards, we have provided full support to the Arduino BLE library. Additional details about the library can be referenced from the documentation provided by Arduino.
Users who haven't already done so, will need to install the Arduino BLE library to continue with this example; please use the guide below, to get started with installing the Arduino BLE library:
Installing an Arduino Library
January 11, 2013
Peripheral LED Example
Note: Users will need to download the NRF Connect app onto their phone. We highly recommend utilizing an Android phone as we have had difficulties with device connections in the app for Apple phones.
As in the prior examples, these steps will follow a similar procedure.
- From the drop down file menu, open the LED sketch: File > Examples > ArduinoBLE > Peripheral > LED.
- Save the sketch (File > Save As...) using the file drop down menu.
- Select the then, export the compiled binary code (Sketch > Export compiled Binary) using the sketch drop down menu.
- Drag and drop (or copy) the binary
.bin
file into theARTEMIS
mass storage drive. The storage drive will automatically eject once the programming is complete. - To verify that the board is working and that the programming was successful, open a terminal emulator, such as TeraTerm or the Serial Monitor in the Arduino IDE. Connect to the serial port for the Artemis DK; don't forget to set the baud rate to 9600 bps.
- Click the reset button to begin the program. Users should see a
BLE LED Peripheral
message in the terminal emulator. - Follow the steps and video below to control the
STAT
LED on the Artemis DK.- Unlock the phone and enable the Bluetooth.
- Open the NRF app.
- Click on the Scan button on the upper right corner.
- In the results, locate the device labeled
LED
. Click on the CONNECT button to the right of the device name.- In the terminal emulator, users should see a
Connected to central:
message followed by the mac address of the phone.
- In the terminal emulator, users should see a
- Once connected, locate the
Unknown Service
. It will have the following service UUID:19B10000-E8F2-537E-4F6C-D104768A1214
. - Click on the service. Then, locate and click on the upload button (up arrow).
- A dialog box will open. We want to write a value, so locate the
New Value
text field, under the Write value drop-down menu option. Based on the control inputs to the LED, anLED on
orLED off
message will appear in the terminal emulator.- Enter
01
to turn the LED on. Then click the SEND button. - Enter
00
to turn the LED off. Then click the SEND button.
- Enter
What About Interrupts?
Interrupts allow users to interrupt the code running in the main loop of their code and execute another set of instructions (with an interrupt handler or interrupt service routine) before returning back to the main loop.
Processor Interrupts with Arduino
December 11, 2018
Check out these Arduino pages for more information on interrupts:
Real Time Operating System (RTOS)
With the incorporation of Mbed™ OS into the Apollo3 Arduino core, to support the Bluetooth functionality, it now functions as a RTOS. This increases the complexity of the code implementation. In order to help users understand how to adapt their code to utilize interrupts, we have provided the following examples for the Apollo3 core: File > Examples > Apollo3 > Pick Example
For more details on the RTOS and interrupt functionality, check out the Mbed™ documentation on scheduling APIs.
Troubleshooting Tips
Below, we have also included some additional troubleshooting tips for issues that you may come across with the Artemis Development Kit.
- One of our employees compiled a great list of troubleshooting tips based on the most common customer issues. This is the perfect place to start.
- For any Arduino IDE specific issues, we recommend starting with their troubleshooting guide.
If neither of the troubleshooting guides above were able to help, here are some tips you might have missed. (Most of this material is summarized from the tutorial.):
Are You Using a Recommended Computer OS?
This board is not compatible with the Arduino Web IDE. We do NOT recommend using a Chromebook, Netbook, tablet, phone, or the Arduino Web IDE in general. If you are here, try a RECOMMENDED operating system.My Board Isn't Working:
Every Artemis board gets tested before getting packaged up. That being said, let's try a basic test to see if just the board is working. Disconnect everything that you have attached to the board; we just want to test the board.- Inspect the board:
Check the board to make sure everything looks about right. Use the pictures on the product page to verify component placement or alignment, and bad solder joints, or damage. - Power and check the status LEDs:
Using a known good USB-C cable, plug your board in to the computer. Do any of the status LEDs turn on?- New boards, out of the bag, usually come programmed with a test sketch. Often it is a sketch that blinks that status LED at a rate of approximately 2 blinks per second.
- Test a Blink sketch:
Try to program the blink sketch. Why blink? It is simple, known to work (from the example files), and you have an indicator LED.- Double check that you have the proper Board selected prior to uploading or exporting the compiled binary.
- For boards that are already running the blink example, I recommend changing the timing parameters to check for a change in the board's response.
- Driver Installation:
The CH340 serial-to-UART chip may require the latest driver to operate properly. For the associated boards, make sure that the driver is up to date. For instructions for updating your driver, please refer to the CH340 driver installation tutorial.
I Don't See My Board on a Serial/COM Port:
If you don't see your board as an available COM port on the Arduino IDE:- Try to re-open the Arduino IDE.
- Check the Device Manager to verify that your computer recognizes the board.
- The issue might be related to your USB cable. Check that you are using a USB cable capable of data transfers. Some cables only have the power pins connected for charging. A good way to test this is to plug in a device to your USB cable (like a phone). If it doesn't show up as a device or drive, then try a new USB-C cable.
- This rarely happens, but it is easy to check. If you are using a USB 3.0 port (you will see a blue "tongue" in the USB jack or bad USB port, try a different USB port. You can also try to test the board on a different computer to double check for a hardware incompatibility (usually with expansion boards).
Errors Uploading to the Board:
There are two types of issues that you will usually see in the console of the Arduino IDE, compile errors or upload errors. The easiest way to see where to start is by clicking the Verify button (check mark); the Arduino IDE will try to compile your code. A failure here is a compile error.It takes a some experience, but if you enable the verbose output from the Arduino IDE preferences, it may give you more clues to where the issue is.
- Compile Errors:
With compile errors, there are several things that could be causing issues. However, 99% of the time, it is user error. Usually something wrong with your code or the library you are using. Once in a while you will have a file structure issue if you manually added a file/folder in any of the Arduino folders (still user error). - Upload Errors:
Upload errors get a little more tricky. You will usually just see the Arduino IDE trying to upload to the board multiple times. There are usually several different causes for this, often without specific errors in the console. Here are a few common examples:- Wrong Board Selection:
Double check you board selection options. If you uploaded with the wrong board selection, there is a small chance that you may have overwritten the bootloader on the board or damaged the microcontroller. - Missing Bootloader:
If your board has the bootloader flashed, pin 13 will flash several times on power up. - Serial Port Interference:
If a device is communicating to the microcontroller over digital pins 0 and 1, while you are trying to upload code. - Bad USB cable or port (see Serial Port section above).
- Wrong Board Selection:
Additional Tips:
- If an input pin is read and that is floating (with nothing connected to it), you may see random data/states. In practice, it is useful to tie an input pin to a known state with a pull-up resistor (to VCC), or a pull-down resistor (to GND).
- There is a maximum amount of current an I/O pin can source (provide positive current) or sink (provide negative current). You can usually power small sections of LED strips or small motors, but will run into issue with high power devices.
- The pins on your board may use 3.3V logic and aren't directly compatible with 5V devices.
Need more help?
If you need technical assistance or information, head on over to the SparkFun Technical Assistance page for some initial troubleshooting.
If you don't find what you need there, the SparkFun Forums are a great place to find and ask for help. If this is your first visit, you'll need to create a Forum Account to search product forums and post questions.
Resources and Going Further
- Related Hardware Information:
- Artemis Module:
- Apollo3 Datasheet (PDF)
- Apollo3 Pad Mapping (PDF)
- Artemis Integration Guide (PDF)
- SparkFun Qwiic Connect System
- Artemis Module:
- Other Software Guides:
- Artemis Development with Arduino (Previous Version)
- Artemis Development with Arm® Mbed™ OS (Beta)
- Artemis Development with Arm® Mbed™ OS (Pending release)
- Artemis Development with the AmbiqSDK
- GitHub Repository for Apollo3 Board Support Packages (BSP)
- Development Platforms for Artemis Module:
- SparkFun Ambiq Apollo3 Arduino Core
.json
file needed for the SparkFun Ambiq Apollo3 Arduino Core:
https://raw.githubusercontent.com/sparkfun/Arduino_Apollo3/main/package_sparkfun_apollo3_index.json
- Mbed™ OS (Ported)
- AmbiqSDK (Ported)
- pyOCD (Ported)
- SparkFun Ambiq Apollo3 Arduino Core
- SFE Product Showcase
Need some inspiration for your next project? Check out some of these related tutorials:
SparkFun Tutorials
Installing an Arduino Library
What is an Arduino?
Installing Arduino IDE
Installing Board Definitions in the Arduino IDE
Arduino Tutorials
Arduino Board Comparison Guides
Choosing an Arduino for Your Project
Standard Arduino Comparison Guide
RedBoard vs. Uno
Click the buttons above for tutorials relating to the board functionality based on topic difficulty.