Xplained Mini First Look

The original purpose of this lab was to test run the new Atmel Xplained Mini board, make sure it is usable, and give feedback on what does/doesn’t work and how to improve it. I was also supposed to take note of any problems I found while going through the lab relating to the board.

In doing so, I encountered a classic road block that can stop a student from getting the device programmed.  Below is the screenshot.  

The error message in the screenshot says:

“Failed to enter programming mode. ispEnterProgMode: Error status received: Got 0xc0, expected 0x00 (Command has failed to execute on the tool). Unable to enter programming mode. Verify device selection, interface settings, target power, security bit, and connections to the target device.”

Note, if you receive an error that you cannot read the data, you may have closed out of a program while the board was in Debug Mode. Open a program, and run it in debug mode, and, in the debug menu, press “Disable debugWire and Close” to fix this issue.

Next, I switched the objective to looking for the differences between the Xplained Mini and the Arduino Duo– a popular microcontroller board with a very similar footprint. Differences were related to their physical properties such as pins and converters–mostly the ADC (Analog Digital Converter) pins.

Home Alarm System- Big Picture

Our team wanted to make our project have a strongly practical application which could prove useful to anyone. With this in mind, we came up with the idea of a home alarm system.

This system is designed to go off when a switch is triggered and then deactivate ONLY when the correct code is entered. The system should also have a on/off switch for turning it on or off before leaving the house. This button will not be able to turn off the system if it is currently alarming. Our home alarm system can be mounted on any door or window and will be triggered to go off when it opens.

Here is our take on a home alarm system.

Home Alarm System – Code

The software for this system implements three states: System Clear, Deactivated, and Alarm Triggered. The code loops while the system is active waiting for the light break sensor to be open indicating that an intruder has broken in. At this point, the code snippet below compares a passcode input by a user to a predefined passcode and acts accordingly. The LCD tells you whether or not the passcode that was entered is correct.

Home Alarm System – Schematics

The circuitry and hardware for our project was rather simple. We had five total buttons, one for on/off toggle and four for the passcode entry. One pin on each button was connected to Vcc on the A3BU and another pin was connected to separate digital pins on the A3BU, then went through a pull down resistor to ground. The passive buzzer has two pins, one connected to the A3BU and one connected to ground. The two LED status lights were connected to ground on one pin, and the other pins were connected to separate pins on the A3BU after going through a resistor. Finally, the photo interrupter had one pin to Vcc, one pin to ground, and the final pin to a digital pin on the A3BU. After the project was functional, we trimmed down the circuit and made it a lot neater. You can see this in the image below. The final image is the circuit schematic for the project.

Xplained Mini Project: Schematics

This part of the “Xplained Mini First Look” project was to compare and contrast the Xplained Mini board with the Arduino Uno, a popular microcontroller board with similar schematics. All I had to go off of for comparing the boards was the schematics and information online about them.

While reading the Arduino Uno webpage, I found that the Arduino Uno is based on the Atmega328 which is also on the Xplained Mini. Below is a screenshot from the Arduino website.

This is one of the block diagrams for the Arduino. The diagram shows in general how things are wired which is why it was useful in finding the ADC.

This is one of the schematics for the Atmega328P showing where on the chip which pins are related to what. It shows which pins are on the chip for the ADC; on this board it is pins 6 and 7.

Temperature Controlled Box – Source Code

#include <asf.h>
#include <stdio.h>

static volatile int16_t last_temperature;
#define INPUT_PIN              ADCCH_POS_PIN1
#define OUTPUT_STR_SIZE        40
struct pwm_config mypwm[4];
int32_t destemp;
#define MY_fan                  IOPORT_CREATE_PIN(PORTA,19)
static void adc_handler(ADC_t *adc, uint8_t ch_mask, adc_result_t result)
int32_t temperature;
char out_str[OUTPUT_STR_SIZE];

/* Compute current temperature in Celsius, based on linearization
* of the temperature sensor adc data.

ioport_set_pin_dir(MY_LED0, IOPORT_DIR_OUTPUT);
ioport_set_pin_dir(MY_LED1, IOPORT_DIR_OUTPUT);
if (result > 697) {
temperature = (int8_t)((-0.0295 * result) + 40.5);
} if (result > 420) {
temperature = (int8_t)((-0.0474 * result) + 53.3);
} else {
temperature = (int8_t)((-0.0777 * result) + 65.1);

last_temperature = temperature;

// Write temperature to display
last_temperature = last_temperature * 1.8 + 32;

if (last_temperature-2>destemp)

snprintf(out_str, OUTPUT_STR_SIZE, "Temperature:%1d F AC  ", last_temperature);
ioport_set_pin_level(MY_LED0, 3.3);
ioport_set_pin_level(MY_fan, 5);
ioport_set_pin_level(MY_LED1, 0);

else if (last_temperature+2<destemp)

snprintf(out_str, OUTPUT_STR_SIZE, "Temperature:%1d F Heat", last_temperature);
ioport_set_pin_level(MY_LED0, 0);
ioport_set_pin_level(MY_fan, 0);
ioport_set_pin_level(MY_LED1, 3.3);
else// if(last_temperature==destemp || (last_temperature-2>=destemp && last_temperature+2<=destemp))

snprintf(out_str, OUTPUT_STR_SIZE, "Temperature:%1d F off ", last_temperature);
ioport_set_pin_level(MY_LED0, 0);
ioport_set_pin_level(MY_fan, 0);
ioport_set_pin_level(MY_LED1, 0);

//            snprintf(out_str, OUTPUT_STR_SIZE, "Temperature: %2d F", last_temperature);
gfx_mono_draw_string(out_str, 0, 0, &sysfont);

// Start next conversion.
adc_start_conversion(adc, ch_mask);

static void adc_handler2(ADC_t *adc, uint8_t ch_mask, adc_result_t result)
char out_str[OUTPUT_STR_SIZE];
if(result>= 65000){
result = 64;
result = (int)(result/22);
if(result < 64){
result = 64;
snprintf(out_str, OUTPUT_STR_SIZE, "Desired Temp: %1d F   ", result);
//result = (int)result/1.2;

gfx_mono_draw_string(out_str, 0, 20, &sysfont);
adc_start_conversion(adc, ch_mask);

int main(void)
struct adc_config         adc_conf;
struct adc_config adc_conf2;
struct adc_channel_config adcch_conf;
struct adc_channel_config adcch_conf2;


// Enable backlight if display type is not OLED

// Initialize configuration structures.
adc_read_configuration(&ADCA, &adc_conf);
adcch_read_configuration(&ADCA, ADC_CH0, &adcch_conf);

adc_read_configuration(&ADCB, &adc_conf2);
adcch_read_configuration(&ADCB, ADC_CH1, &adcch_conf2);

/* Configure the ADC module:
* - unsigned, 12-bit results
* - VCC voltage reference
* - 200 kHz maximum clock rate
* - manual conversion triggering
* - temperature sensor enabled
* - callback function
adc_set_conversion_parameters(&adc_conf, ADC_SIGN_ON, ADC_RES_12,
adc_set_clock_rate(&adc_conf, 200000UL);
adc_set_conversion_trigger(&adc_conf, ADC_TRIG_MANUAL, 1, 0);
adc_enable_internal_input(&adc_conf, ADC_INT_TEMPSENSE);

adc_set_conversion_parameters(&adc_conf2, ADC_SIGN_ON, ADC_RES_12,
adc_set_clock_rate(&adc_conf2, 200000UL);
adc_set_conversion_trigger(&adc_conf2, ADC_TRIG_MANUAL, 1, 0);
adc_enable_internal_input(&adc_conf2, ADC_INT_TEMPSENSE);

adc_write_configuration(&ADCA, &adc_conf);
adc_set_callback(&ADCA, &adc_handler);

adc_write_configuration(&ADCB, &adc_conf2);
adc_set_callback(&ADCB, &adc_handler2);

/* Configure ADC channel 0:
* - single-ended measurement from temperature sensor
* - interrupt flag set on completed conversion
* - interrupts disabled
adcch_set_input(&adcch_conf, ADCCH_POS_PIN1, ADCCH_NEG_NONE,
adcch_set_interrupt_mode(&adcch_conf, ADCCH_MODE_COMPLETE);

adcch_write_configuration(&ADCA, ADC_CH0, &adcch_conf);

// Enable the ADC and start the first conversion.
adc_start_conversion(&ADCA, ADC_CH0);

adcch_set_input(&adcch_conf2, ADCCH_POS_PIN1, ADCCH_NEG_NONE,
adcch_set_interrupt_mode(&adcch_conf2, ADCCH_MODE_COMPLETE);

adcch_write_configuration(&ADCB, ADC_CH1, &adcch_conf);

// Enable the ADC and start the first conversion.
adc_start_conversion(&ADCB, ADC_CH1);

do {
// Sleep until ADC interrupt triggers.
} while (1);

Temperature Controlled Box – Final Build

The final build of our project was successful in creating a +7 degrees Fahrenheit change in less than 1 minute, and a -7 degrees Fahrenheit change in less than 3 minutes. We could have pushed our system further, although we found this temperature range to be fitting of realistic temperature settings in traditional HVAC systems. In any case, the project fulfilled its designed purpose.


Despite the project being a success, there were a few issues and design changes which we did not implement but would have improved the overall functionality of the system. Once obtaining a desired temperature, the system would not rerun a heat or cold mode until the actual temperature dropped below or rose above 2 degrees of the ideal (assuming the ideal temperature had remained constant). This was so the fan or hair dryer would not be turning rapidly off and on. When the room reached a sub 72 temperature, the fan would not reactivate for some time, however the hair dryer would never last more than 10 seconds. This is likely due to the moderate insulation of the control room, which could have been improved by sealing off gaps more tightly and adding a layer or two of higher insulating material.


Another minor issue we had was the npn transistor eating a small about of voltage when passing VCC, which decreased the overall speed of the fan. We considered using a different transistor to see if it consumed less voltage, but the cooling process operated in a reasonable amount of time so we decided to leave it. This would be an ideal fix, however, if a smaller cooling time is desired. It is also important to note there may have been some current loss due to the potentiometer also being connected to VCC in parallel, so it may have been a good idea to throw on a resistor in series and recalibrate the potentiometer values to fit the new, probably smaller, voltage range.


Despite these minor setbacks, the project turned out almost better than expected. The enclosures were well constructed, everything fit together nicely, and we even had a laser engraved decal [done at First Build] on the front and top of the control room, with our names and the project logo. Overall, we were able to successfully build our designed project, and every team member did their share of work towards the final completion.

Temperature Controlled Box – Software

For the code portion of this project, we used Atmel Studio 7 on Windows 10 OS and, per usual, did not experience any interface issues.


Using the ADC handler we were able to monitor the current temperature. Inside this handler we output the current temperature and used if statements to decide whether we needed to turn on the fan or the hair dryer. Inside the second handler we monitored readings of the potentiometer. Before we did this, however, we manipulated the result so that we had the correct desired temp. We divided the result by 1.2, yielding a Fahrenheit scale of +/- 12 degrees from 72, and made sure that any undesirable values we got from the potentiometer when it was turned all the way to either side were removed. The desired temperature was a global variable that was compared in the first ADC handler. IOPORT_CREATE_PIN was used to create and output pin My_LED0, My_LED1, and My_FAN. Pins 17, 16, and 19 were then used to toggle the desired pin the command ioport_set_pin_level (which would be the desired pin; an INT with desired value). Since the enclosure leaked temperature we had to add an offset to the desired temperature so that we could show off the off functionality. To toggle the on-board LEDS we used the commands gpio_set_pin_low() and gpio_set_pin_high() as necessary. For outputting current temperature and the desired temperature on the LCD, we used a char array out_str and snprintf(out_str, OUTPUT_STR_SIZE, “Temperature: %2d F”, last_temperature) so that we could have the string on the screen update with every read of the temperature. Finally, we used gfx_mono_draw_string to actually generate the output on the LCD. The complete program can be found in the source code.

Temperature Controlled Box – Hardware

During the design phase of this project, we experimented with several ideas about most aspects of the project. Once we agreed about designing a temperature regulator, we knew fairly early on that we were going to use a hair dryer as our heat source, as the magnitude of hot air would be extremely effective for such a small enclosure. This proved to be the case once the project entered the testing phase.


The cold source, however, took a bit more planning. Our first design consisted of a small thermos filled with an ice bath with tubing placed directly over the water, with the other end inserted in the control room, with a fan somewhere in the middle. This design was abandoned fairly early due to multiple issues, primarily the moisture concern and building complexity of the model. Additionally, we were concerned that the effective cooling of this system would be insufficient. Our final design was much simpler to construct and proved to be effective enough for our purposes. We would house several ice packs in a wooden box that would sit directly next to the control room, with the fan directly between the two. The input/output holes were placed near the top and bottom of the reservoir on opposite sides, as to allow maximum air exposure to the ice packs.


Moving on the circuitry of the system, we utilized the temperature sensor and LCD screen of the A3BU, as well as the following pins, whose functions are summarized:


J1_VCC – Cold Reservoir Fan Power / Potentiometer Power

J1_TxD – NPN Transistor Base

J1_SDA – Blue LED

J1_SCL – Red LED/Relay Switch

J2_ADC1 – Potentiometer Sensor

J2_GND – Ground


The circuit runs in three different modes – off, heat, and cold. In all modes, VCC and ADC1 are constantly active, in order to figure out the desired temperature based off the resistance of the potentiometer. Off occurs when no other pins are active, and the actual temperature equals the desired temperature. The desired temperature is changed by rotating the potentiometer dial, which signals to ADC1. When the desired temperature is greater, SCL activates which both switches the relay outlets (turning on the hair dryer), and the red LED is powered on, indicating that the system is in heat mode. When the desired temperature is less, both TxD and SDA come on. TxD enables flow through the transistor, allowing VCC to power the fan, and SDA powers the blue LED, indicating cold mode. Once obtaining a desired temperature, the system will not rerun a heat or cold mode until the actual temperature drops below or rises above 2 degrees of the ideal (assuming the ideal temperature had remained constant).This circuit can be viewed in full in the schematic.