Archive

For the Arduino category

Maximum frequency an Arduino can generate

No Comments

What is the maximum frequency an Arduino can generate? Typically, I obtained a frequency of less than 100 kHz using the Arduino function calls. The results were lower than I expected. I also observed that I had a frequency higher by 25 kHz using a pin from the 8 to 13 pin set than a pin from the 0 to 7 pin set. These tests yield a virtually perfect waveform. I obtained almost 4 MHz by accessing the register directly. The waveform was not as good as the waveform of the first four tests. The waveform is given in Figure 1.

Sketch 1 Frequency: 72.6 kHz
Duty Cycle: 47.7%
#include

#define OUTPUT_PIN 3

void setup() {
  pinMode(OUTPUT_PIN, OUTPUT);
}

void loop() {
  digitalWrite(OUTPUT_PIN, HIGH);
  digitalWrite(OUTPUT_PIN, LOW);
}

Sketch 2 Frequency: 74.3 kHz
Duty Cycle: 49.2%
#include

#define OUTPUT_PIN 3

void setup() {
  pinMode(OUTPUT_PIN, OUTPUT);
}

void loop() {
  while(1) {
    digitalWrite(OUTPUT_PIN, HIGH);
    digitalWrite(OUTPUT_PIN, LOW);
  }
}

Sketch 3 Frequency: 96.94 kHz
Duty Cycle: 49%
#include

#define OUTPUT_PIN 8

void setup() {
  pinMode(OUTPUT_PIN, OUTPUT);
}

void loop() {
  digitalWrite(OUTPUT_PIN, HIGH);
  digitalWrite(OUTPUT_PIN, LOW);
}

Sketch 4 Frequency: 96.94 kHz
Duty Cycle: 49%
#include

#define OUTPUT_PIN 8

void setup() {
  pinMode(OUTPUT_PIN, OUTPUT);
}

void loop() {
  while(1) {
    digitalWrite(OUTPUT_PIN, HIGH);
    digitalWrite(OUTPUT_PIN, LOW);
  }
}

Sketch 5 Frequency: 3.97 MHz
Duty Cycle: 25.6%
#include

void setup() {
  DDRB = B00000001;
}

void loop() {

  while(1) {
    PORTB = 0xff;
    PORTB = 0x00;
  }
}

Click on the image to improve the quality.

Wave generated by modifying directly the port

Figure 1: Waveform generated by modifying directly the port (Sketch 5)

STM32 Minimum System Development Board

5 Comments

Upload code to a STM32 Minimum System Development Board

This post describes how to upload code to a STM32 Minimum System Development Board that can be bought from Ali Express or eBay for around $4.00 US. You will be able to compile and upload a led blinking program to the board at the end of this guide. This guide is using Arduino_STM32 by Roger Clark.
You will need:

  1. to download Roger Clark’s Arduino IDE STM32 board support files. It can be downloaded from this link.
  2. to download the latest Arduino IDE. It can be downloaded from this link.
  3. a USB to TTL Serial Cable that uses 3.3V signal level such as link or any equivalent cable.

The setup steps are:

  1. First, install the Arduino IDE following the provided instructions.
  2. Install Arduino SAM Boards (32 bits ARM Cortex-M3) using the Arduino IDE option Tools -> Board -> Boards Manager.
  3. Locate the hardware folder within the Arduino IDE installation folder.
  4. Un-archive the STM32 support files in the hardware directory found in the Arduino IDE installation folder.  Rename the top folder Arduino_STM32-master to Arduino_STM32.  If you restart the Arduino IDE, you will find in the Tools -> Board option a new set of boards including the STM32F103C Series.
  5. Connect the TTL Serial Cable ground pin to one of the ground pins of the board labeled G.   It is the black wire on the picture below. The TTL Serial Cable shall be disconnected from the PC at this stage.
  6. Connect the TTL Serial Cable 5V to the pin labeled 5V on the board.  It is the red wire on the picture below.  A 3.3V supply can also be used.  In this case, connect the 3.3V supply to a pin labeled 3.3 on the board.
  7. Connect the TTL Serial Cable RX pin to the board A9 pin. It is the white wire on the picture below.
  8. Connect the TTL Serial Cable TX pin to the board A10 pin. It is the green wire on the picture below.
  9. Set the jumpers.  Boot0 shall be set to 1 (HIGH) and Boot1 to 0 (LOW).  The Boot1 jumper is right beside the reset switch.
  10. Plug the TTL Serial Cable to the PC.  A red led should light up on the board indicating that it is powered.

The board setup looks like this using an Adafruit 954 TTL Serial Cable.

Upload code to a STM32 Minimum System Development Board

STM32 Minimum System Development Board Wiring

In the Arduino IDE:

  1. Create a new sketch (File -> New).
  2. Copy the code below.  It will make the onboard led blink.
  3. Select the board  Generic STM32F103C Series from the Tools -> Board option.
  4. Select STM32F103C8 (20k Ram, 64 k Flash) from Tools -> Variant option.
  5. Select Serial from the Tools -> Upload method option.
  6. Select the port of the TTL Serial Cable from the Tools -> Port option.
  7. Verify the sketch (Sketch -> Verify/Compile).
  8. Hit the reset button on the board and wait 4 seconds.  If you do not wait enough, you will get a “Failed to init device.” message.
  9. Upload the sketch to the board (File -> Upload).  You will get a bunch of messages.  The last line will be “Starting execution at address 0x08000000… done.”.
  10. The green led will now blink.

If you reset the board or unplug it, your program will not run unless you set both Boot0 and Boot1 jumpers to 0 (LOW).

The test sketch is:


void setup() {
pinMode(PC13, OUTPUT);
}


void loop() {
digitalWrite(PC13, HIGH);
delay(100);
digitalWrite(PC13, LOW);
delay(100);
}

An Arduino library for the MAX7219 Led Display Driver.

No Comments

The MAX7219 chip does a wonderful job when its time to drive either a 64 led matrix or an eight digit (seven segments) display. Only three wires are required: a chip select (CS), a data in (DIN) and a clock (CLK). The protocol is simple. I’ve written an Arduino library that implements this protocol. Specifications can be found at MAX7219.

The library comes with some code examples. Look in the File >> Examples >> CTTMAX7219 sub-menu in the Arduino IDE. Refer to the display and chip manufacturers to hook the display to the MAX7219 chip. This is straight forward. The display will likely need an external supply. If so, make sure that the Arduino board and the chip have a shared ground. You will need to modify the example code to specify the pins used to connect the DIN, CS and CLK pins of the chip to the Arduino. By default, these are:

/** Clock pin on the arduino. */
int pinCLK = 10;
/** Chip select pin on the arduino. */
int pinCS = 9;
/** Data IN on the arduino. */
int pinDIN = 8;

The download link of the library is CTTMAX7219_v1.0. You can install it through the Arduino IDE using the usual methods. Detailed information can be found at Installing Additional Arduino Libraries.

Trinket Support On Linux

No Comments

The Trinket (Adafruit’s Trinket) can be supported on Linux using the Arduino IDE 1.0.5 in only a few steps.

  1. Download this archive: TrinketHardwareSupport
  2. Install the Arduino IDE. It is assumed below that the main directory is arduino-1.0.5.
  3. Replace the current avrdude.conf in arduino-1.0.5/hardware/tools with the one in the downloaded in the archive. It is recommended that you make a backup of the current avrdude.conf file.
  4. Open a terminal window and run the Arduino IDE as root. You can issue the following command as long as the current directory is the Arduino directory where you installed it (arduino-1.0.5).

    sudo ./arduino

  5. Quit the Arduino IDE
  6. A directory called sketchbook should have been created in /root.
  7. Copy the directory hardware from the downloaded archive in /root/sketchbook.
  8. Within the Arduino IDE, from the Tools/Board menu item, select Adafruit Trinket 8 MHz
  9. Within the Arduino IDE, from the Tools/Programmer menu item, select USBtinyISP

A simple test can be done assuming that the Trinket is plugged on the PC.

  1. From File/Examples/01.Basics, select Blink
  2. Change value of the global variable led to 1.
  3. Upload the sketch to the Trinket
  4. The red led on the Trinket should be blinking.

How to restore the Arduino Bootloader?

No Comments

It can be easily done using Linux. This procedure is for the 328p processor. It can easily be adapted for a 168 processor. You will need an ICSP. First, make sure that avrdude is installed. It can be installed by issuing the command:

sudo apt-get install avrdude

You will need to retrieve the bootloader. It can be found in the hardware/arduino/bootloaders/atmega directory in the 1.0.5 Arduino IDE download. It is named ATmegaBOOT_168_atmega328.hex.

  1. Put the chip on an Arduino board.
  2. Connect the ICSP to the Arduino board.
  3. Power the Arduino with an external source.
  4. Connect the ICSP to the computer. Find its serial port. Most of the time, it is listed in the system log. The command ‘dmesg’ can be used to find it out. Look at the last lines.
  5. Open a command line window.
  6. Issue the following commands. Replace /dev/ttyACM0 by the proper ICSP port.
    /usr/bin/avrdude -c avrispv2 -p m328p -P /dev/ttyACM0 -e

    /usr/bin/avrdude -c avrispv2 -p m328p -P /dev/ttyACM0 -U flash:w:ATmegaBOOT_168_atmega328.hex

  7. Unplug the ICSP and reset the Arduino board.

Mounting plate for Arduino UNO/Duemilanove/Diecimila

No Comments

A “Mounting plate for Arduino UNO/Duemilanove/Diecimila” is now available. More details at Mounting plate for Arduino UNO/Duemilanove/Diecimila.

Installation of the AVR toolchain on Ubuntu to develop for the Arduino Platform

No Comments
  1. Install Eclipse using “Ubuntu Software Center”
  2. Install the AVR Eclipse Plugin using Help >> Install New Software. The source link is http://avr-eclipse.sourceforge.net/updatesite/
  3. Install the gcc toolchain
apt-get install avrdude binutils-avr gcc-avr avr-libc gdb-avr

Arduino Ethernet Shield example WebServer.pde no longer works after upgrading Ubuntu to version 11.10

No Comments

This patch must be applied to w5100.h located into library/Ethernet/utility.

--- w5100.h.orig	2011-10-03 13:43:10.536833701 +0200
+++ w5100.h	2011-10-03 13:47:26.764844567 +0200
@@ -258,7 +258,10 @@
   }                                                          \
   static uint16_t read##name(SOCKET _s) {                    \
     uint16_t res = readSn(_s, address);                      \
-    res = (res << 8 ) + readSn(_s, address + 1);             \
+    uint16_t res2 = readSn(_s,address + 1);                  \
+    res = res << 8;                                          \
+    res2 = res2 & 0xFF;                                      \
+    res = res | res2;                                        \
     return res;                                              \
   }
 #define __SOCKET_REGISTER_N(name, address, size)             \
Blue Taste Theme created by Jabox