Programming various Atmel chips

This is meant to be a compendium of programming guides for a series of useful Atmel chips.

Diagram of the Arduino Uno, which will be used to program each of these chips:

ATmega328P

Diagram:

One time: burning the bootloader

  1. Connect an unwired Arduino to the computer.
  2. Set Tools/Board to “Arduino/Genuino Uno” and upload the example ArduinoISP sketch.
  3. In Documents/Arduino, create a new folder called “hardware”.
  4. Download breadboard-1.6.zip and unzip it in the hardware folder. The final directory tree should look like this:
  5. Restart the Arduino IDE.
  6. Wire the devices as shown.
  7. Connect a 10 µF capacitor from reset to ground on the Arduino.
  8. Set Tools/Board to “ATmega328 on a breadboard (8MHz internal)”.
  9. Set Tools/Programmer to “Arduino as ISP”
  10. Click Tools/Burn Bootloader.
  11. Post the error it gives you in the comments below. (hopefully none)

Every time: uploading sketches

  1. Set Tools/Board to “ATmega328 on a breadboard (8MHz internal)”.
  2. Set Tools/Programmer to “Arduino/Genuino Uno”
  3. Wire the device like shown.
  4. Press the upload button.

ATmega328 (without the P)

Seriously consider buying a regular ATmega328P unless this is all they have at your local electronics store.

One time: burning the bootloader

Follow the same instructions as for ATmega328P, but after step 3 edit “boards.txt” within Arduino/hardware/breadboard/avr. Find the line that reads “atmega328bb.build.mcu=atmega328p” and change atmega328p to atmega328. After step 9, revert this change (the bootloader causes the chip to respond in the same way as a ATmega328P).

Every time: uploading sketches

Same instructions as for ATmega328P

ATtiny84 (14-pin DIP)

No bootloader is required.

Diagram:

Uploading sketches:

  1. Connect an unwired Arduino to the computer.
  2. Set Tools/Board to “Arduino/Genuino Uno” and upload the example ArduinoISP sketch.
  3. Open Arduino’s preferences. In Additional Boards Manager URLs, insert https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json and press OK.
  4. Go to Tools/Boards/Boards Manager. Search for attiny. Click the first result and press Install.
  5. Restart the Arduino IDE.
  6. Wire the board as follows.
  7. Set Tools/Board to ATtiny24/44/84
  8. Set Tools/Processer to ATtiny84
  9. Set Tools/Clock to 1MHz
  10. Set Tools/Programmer to Arduino as ISP.
  11. Click Sketch/Upload using Programmer.

ATtiny85 (8-pin DIP)

No bootloader is required.

Uploading sketches:

Follow the instructions for the ATtiny84. For step 6, wire the board as follows:

For step 7, select ATtiny25/45/85. For step 8, select ATtiny85.

 

Sources:

  • https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard
  • http://42bots.com/tutorials/programming-attiny84-attiny44-with-arduino-uno/
  • http://42bots.com/tutorials/how-to-program-attiny85-with-arduino-uno-part-1/
  • http://www.pighixxx.com/

Object Detection with DIGITS and Caffe

This is a simplified version of the notes I took while creating and training a neural network to detect balls in the FRC 2017 game. This will be further updated with additional detail as time allows.

Requirements: Vatic, DIGITS, NvCaffe

An input data set of images with the object for detection in the target environment needs to be captured. About one minute of HD video at 30 FPS should be sufficient.

In order for DetectNet to find the location of the bounding boxes, it needs to know the ground truth position and location of these in the training data set. Vatic can be used for this process as it will allow for the division of effort of annotating the objects in the images between multiple individuals, and it requires very little training of the operators.

The output.txt file produced by vatic details the bounding box locations for each frame of the input image. A python script is then used to extract the frame numbers and dimensions from this file and build the folder structure demanded by DetectNet, which is the same as the KITTI data set. The layout appears as follows:

./train
./train/images
./train/images/00001.jpg
./train/labels
./train/labels/00001.txt
./val
./val/images
./val/images/00001.jpg
./val/labels
./val/labels/00001.txt

In DIGITS, create a new object detection data set with the folders as described above. In order to use the original DetectNet network without modification, adjust the padding and resize options so the final output size is 1248×384. For images with heights greater than 384, this may first involve padding to fit the image to a 3.25 aspect ratio followed by a resize. The remainder of the settings here can be left as default, and modification of custom classes can be avoided by simply using class names from the KITTI dataset, such as car or pedestrian for the new input.

Then, create a new object detection model from this dataset. Set training epochs to 100, batch size to the graphics card’s limits (a batch size of 10 requires 12 GB of dedicated video memory), solver type to Adam, learning rate to 0.0001, and policy to exponential decay. Disable mean image subtraction. Choose custom network and paste the contents of the reference DetectNet network. To speed learning, download the pretrained weights for the GoogLeNet network to the computer running DIGITS and set the path below accordingly. Click create to begin training.

The model will begin training, and may take hours even on top of the line graphics cards. The output named mAP is close to percentage accuracy for this task and it will increase from zero if the model is learning.

Final output:

Predicting the Presence of Cancer in Medical Images using Convolutional Neural Networks

Paper submitted to Missouri Junior Science, Engineering, and Humanities Symposium for 2017

Abstract:

Convolutional neural networks model human brain activity from sensory inputs and have been applied to various activities such as driving cars, recognizing speech, and playing complex games. These machine learning algorithms gained popularity in recent years as an effective method for pattern recognition. This paper proposes a novel convolutional neural network architecture to detect lung cancer in radiographic images. Given that patients routinely have x-rays taken for pre-emptive health screenings, and the growing amount of medical data from these imaging procedures, the need for automated detections of abnormalities increases. The solution used a dataset of labeled x-ray images of patients with confirmed instances of lung cancer combined with an equal set of cancer-free patients. The network relied on rectified linear unit activations and dropout to reduce overfitting. Then, this neural network model was trained with a standard backpropagation algorithm with an Adam optimizer using softmax regression. This model demonstrated a 91% accuracy rate on lung cancer chest x-rays.

Cite:

@article{monahan2017,
title = {Predicting the Presence of Cancer in Medical Images using Convolutional Neural Networks},
author = {Monahan, Connor},
note =
{preprint on webpage at \url{connormonahan.net}},
year = {2017}
}

Article (PDF)

Depth Image Segmentation Using Statistical Methods

Paper presented to the Junior Science, Engineering, and Humanities Symposium at Maryville University in 2016.

Abstract:

This paper presents an algorithm that utilizes unsupervised machine learning methods for
classifying n-objects in a spatial image. Other methods of spatial image segmentation, for
example the Laplacian operator and support vector machines (SVM), solely return all visible
edges within the image, which can then be used to find all objects within the frame; however,
this algorithm returns all points belonging to a specific object in the image rather than the edges
of the entire image. This allows the omission of further processing and categorizes all the present
data into classes using a modification of the Otsu thresholding method, by using a spatial metric
and optimizing the local minimum to the partial derivative of an n-modal distribution.
Implementation of the algorithm can be specialized to work on any list of points, such as an
entire image or a region of an image. The results of the algorithm return distinct information for
each object in the image, allowing further processing to determine other characteristics about the
object, such as the orientation.

Cite:

@article{monahan2016,
title = {Depth Image Segmentation Using Statistical Methods},
author = {Monahan, Connor},
note =
{preprint on webpage at \url{connormonahan.net}},
year = {2016}
}

Article (PDF)

Local Positioning System with Multiple Cameras

Paper presented to the Junior Science, Engineering, and Humanities Symposium at Maryville University in 2015.

Abstract:

This paper presents the process of obtaining, filtering, and tracking targets to obtain the
camera’s relative position. The program used computer specific architecture features to optimize
the program and provide consistent results immediately. First, images are obtained of the
environment from 3 different infrared cameras in gray-scale with a field of view of 120 degrees.
Next, the images underwent a series of image processing algorithms using the OpenCV
programming libraries, such as morphological transformations and binary topological analysis, to
identify the targets in the image. This converts the 1080p 1-channel matrix into a vector of points
called contours. A series of tests were then used to remove potential noise and error from the
data. The program then uses vectors and matrices as storage for calculating the positioning and
distance. At this point the information from each camera was combined and utilized in a GPS
style calculation was used to find the local position of the robot relative to the field. Finally, this
information was used to solve for the relative pose of the robot by solving a system of non-linear
functions. The results provide positioning and motion information of the robot relative to the
static environment.

Citation:

@article{monahan2015,
title = {Local Positioning System with Multiple Cameras},
author = {Monahan, Connor},
note =
{preprint on webpage at \url{connormonahan.net}},
year = {2015}
}

Article (PDF)