Leonardo
ATmega328 PDIP
| | AD8 is termperature
ADC7 ADC6 only on 32MLF package |
32MLF package used in ethernet board has very different pin numbering and includes ADC6 and ADC7!
Arduino libraries (setMode,digitalWrite,digitalRead
) refers to pins by their digital BOARD number,
i.e. : PD0
:0; PD1
:1, … ,PB0
:8;PB1
:9, … PB5
:13; … (PB6,PB7 used for XTAL),
PC0
:14 … PC5
:19
pins_arduinoDGG.h,standard/pins_arduino.h,
micro,
mega,
leonardo
port A is not defined!i
28 pin packages do not have ADC6, ADC7.
DB6 and DB7 are XTAL and therefore unavailable. This causes arduino numbering oddities i.e. DB6=6; DC0=7
// symbols and macros from arduino.h
HIGH LOW INPUT OUTPUT true false
SERIAL
DISPLAY
LSBFIRST MSBFIRST
CHANGE FALLING RISING
DEFAULT
EXTERNAL INTERNAL INTERNAL1V1 INTERNAL2V56
interrupts() sei() noInterrupts() cli()
clockCyclesPerMicrosecond()
clockCyclesToMicroseconds(a) microsecondsToClockCycles(a)
bitRead(value, bit) bitSet(value, bit) bitClear(value, bit) bitWrite(value, bit, bitvalue)
analogInPinToBit(P)
digitalPinToPort(P) digitalPinToBitMask(P) digitalPinToTimer(P)
portOutputRegister(P) portInputRegister(P) portModeRegister(P)
NOT_A_PIN NOT_A_PORT
PA PB PC PD PE PF PG PH PJ PK PL
NOT_ON_TIMER 0
TIMER0A TIMER0B TIMER1A TIMER1B TIMER2 TIMER2A TIMER2B
TIMER3A TIMER3B TIMER3C TIMER4A TIMER4B TIMER4C TIMER4D TIMER5A TIMER5B TIMER5C
__DATE__ __TIME__ The date & time this sketch was compiled
bit(b) word(...) lowByte(w) highByte(w)
constrain(amt,low,high)
min(a,b) max(a,b) abs(x)
round(x) sq(x) ((x)*(x))
PI HALF_PI TWO_PI DEG_TO_RAD RAD_TO_DEG radians(deg) degrees(rad)
Defined in avr/io.h
RAMEND last on-chip RAM address.
| XRAMEND last possible RAM location that is addressable.
for devices that do not allow for external RAM. equal to RAMEND
For devices that allow external RAM, this will be larger than RAMEND.
| E2END last EEPROM address.
| FLASHEND in the Flash program space.
| SPM_PAGESIZE For devices with bootloader support, the flash pagesize (in bytes) to be used for the SPM instruction.
| E2PAGESIZE size of the EEPROM page.
| | | | | | |
THe hardware bit flags are defined as the bit number not as a bit flag. For example DORD is 5 not 0x20.
This necessitates code like SPCR| 1<<DORD
not SPCR|DORD
This is an ATmel convention.
SD/RTC shield schematic
Rose colored rows are dedicated, that is they cann not be used for anything else.
|
| Real Time Clock related DS1307 includes 56 bytes battery backedup RAM
| SDA | | Serial Data to/from DS1307 | No other lines are needed!
See Section 21 for ALL TWI details
| SCL | | Serial Clock Line to DS1307
| SD Card related (uses SPI (Serial Peripheral Interface))
| Arduino | Atmega name | SD
| D10 | CS | PB2 | Chip select for SD | pulled up to 5V
| D11 | MOSI MasterOutSlaveIn DATAout |
| D12 | MISO MasterInSlaveOutDATAin | |
| D13 | SCK | SCKIN | | N.B. SCK same as LED_BUILTIN on Duemilanova
| | | WP | Write Protect
| | | CD | Card Detect
| LEDS
| L1,L2 are unconnected, that is they need to jumpered to a data pin to be used. pin listed is suggestion based on example sketch
| D3 := 3 | L1 | Red
| D2 := 2 | L2 | Green
| | |
|
When coding, use pin function like SCK
not 19 since that's the pin number only for the ATmega328 PDIP package!
SPI ATmega section 18†
The SPI module is enabled by setting SPE of SPCR (As long as its Power Reduction flag PRSPI
† is not set.)
Data is shifted from Master to Slave on the Master Out - Slave In (MOSI ) line, and from Slave on Master In - Slave Out(MISO ).
On the master, the program clears SS for the specific slave device.
Writing to SPDR initiates the transfer. When compete, End of Transmission Flag( SPIF ) is set and an interrupt may be triggered.
The master the sends another byte or sets SS
SPDR - SPI Data Register
SPSR - SPI Status Register
- SPIF: SPI Interrupt Flag
- WCOL: Write COLlision
- SPI2X: SPI double Speed see SPR1 and SPR0
SPCR control†
- SPIE: SPI Interrupt Enable
- SPE: SPI Enable (need to clear for
- DORD: Data ORDer one: LSB transmitted first.
- MSTR: Master (Slave )
- CPOL: Clock POLarity one:SCK is high when idle.
- CPHA: Clock PHAse
- SPR1 SPR0:clock rate (see ATmel table 18.5; f_osc/128 = 112 aka 3 with SPI2X=0)
|
Serial I/O; Universial Synchronous and Asynchronous serial Receiver and Transmitter
register map
- sends and receives bytes,
on a pair of lines, a bit at a time,
autonomously ( i.e. with CPU intervention only needed to load or retrieve each byte).
- Timing with respect to the other device can be either
- synchronized: permitting a block of bytes to be transfered
(
UMSELn master/slave)See SPI mode
- Asynchronously: with bytes occuring at undefined intervals (but no more frequently than with 1 interviening bit time).
The USART is responsible with generating the start and stop timing delays (bits)
- USART Baud Rate Register (
UBRRn ) values depend on the Frequency Of System CLock (See ATmel section 19.11)
baud | FOSC | UBRRnH+UBRRnL | U2Xn
| 9600 | 16MHz | 103 | 0
| 57600 | 16MHz | 16 | 0
| 115200 | 16MHz | 8 | 0
|
- FrameFormat set via
UCSRnB.UCSZn2:0, UCSRnB.UPMn1:0 and UCSRnB.USBSn UCSRnB and UCSRnC. (_)?
- SPI mode:
| |
http://arduino.cc/en/Guide/Environment
Language Reference,
local version
http://arduino.cc/en/Main/Software
Git Guide
For MacOSX use Arduino.app found in arduino-1.0-macosx.zip
After you have everything ready and try to remember what your did:.
- A directory named
xxx
has xxx.pde
source(s) in ASCII text
- Start up Arduino.app
- open the tools/serial monitor ⇑ ⌘ M
- file/open ⌘O your file
- compile and upload ⌘U
Points of interest:
- Arduino IDE monitor does not handle ␍ (it's not an ANSI terminal emulator)
Serial.print
, goes to tx port, is asynchronous, flush() waits for completion
- serial port (tx rx) can be used for other functions after
Serial.end();
- memory: ATmega328P: flash(code,uploaded to):32K, SRAM(data):2K, EEPROM(static data, writeten/read to/from):1K
ATMega48: 4,512,256; 88:8,512,1; 168:16,512,1
#include <avr/pgmspace.>
PROGMEM prog_uint16_t speeds[] = { 300, 19200, 57600 };
PROGMEM prog_uchar signMessage[] = {"I am a big long string with a null terminator");
strcpy_P
copies a string from flash to a string in RAM
example
hexdump -C
char mess[] = "test";
copies 5 bytes from flash to SRAM
#include <EEPROM.h>
EEPROM.write(i, i);
(takes 3.3ms)
value = EEPROM.read(a);
(write seldom, read often)
Serialport port: 1 | 2 | 3 (default 1)
|
---|
int Serial.available() number of bytes are available to read from the serial buffer, max 128
if (Serial.available() > 0) { incomingByte = Serial.read()};
int Serial.read()next byte from buffer; -1 if empty
| Serial.print(str)
| Serial.print(inByte[, fmt] )
fmt:
- DEC decimal default
- BYTE single byte
- HEX hexadecimal (not zero filled)
- OCT octal
- BIN binary as ASCII string 00000000
| Serial.println() outputs a carriage return and a linefeed.
| Serial.println(str) outputs str
| Serial.println(b) outputs b as a decimal number in an ASCII string followed by a carriage return and a linefeed.
| Serial.begin(long rate)
rate : 300| 1200| 2400| 4800| 9600| 14400| 19200| 28800| 38400| 57600| 115200.
Or other special
| | | | | | | | | |
# B......
Arduino has has pins for analog input,
for soures ranging from 0 to 5 volts, ( Aref is connected to VCC) .
These are convert it to a number between 0 (0 volts) and 1023 (5 volts) (10 bits of resolution).
oomlout
| bits | bytes | range
|
byte ddd | 8 | 1 | 0 - 255
|
int ddd | 16 | 2 | -32768 - 32767 0xFFFF
|
unsigned int
word ddd | 16 | 2 | 0 - 65535
|
long nnnnnL 32 | 4 | -2147483648 - 2147483647 max 0x7FFFFFFF
| 128; 33888u; 0xFFFF; 0x01FFFFL; 0777; B1011;
| |
From "Arduino notebook v1-1" :float
…32bit -3.4028E+38 to 3.4028E38
O'baka
compiler output sample
Arduino wiki, forum
AMTEL AVR
avr libc
Ardweeny
eeprom.h tersified
Why:
- using DB6 hardware reset? ∃ a
soft_reset();
- RAM used for hardware register (copies)
- EEPROM retention: O-buffer discussion/ implementation: should store DATA first THEN buffer index. DISABLES?
FTDI Header:
cable | 1 2 | 3 | 4 | 5 | 6 |
| header | DSR | TxD | RxD | Vcc | RTS | Gnd
| correct | DTR RxD | TxD | Vcc | CTS | Gnd
| flipped over | Gnd | CTS | Vcc | TxD | RxD | DTR
| | |
Two Row 1 MISO, 3 SCK, 5 rst
2 Vcc, 4 MOSI, 6 GND
A "complete" hexdump.ino
Collected documents
- ATmega.pdf
- AVR100_AccessingEEPROM.pdf
- AVR101_EEPROMendurance.pdf
- AVR103_Timers.pdf Timer0 is used by the Arduino library functions
micros,mills,delay,delayMicroseconds
(wire.cpp)
- AVR126_ADC.pdf
- AVR134_RTC.pdf
- AVR4027optimize.pdf
- AVR448_3PhaseMotor.pdf
- AVRinstSet.pdf
- DS1307.pdf
- Roobma Library
- Embedds.com tutorials
DNS
- Nanonode
- pololu.com/
- BDMicro MAVRIC $159
- Arduino to Twitter over USB
- ADAFruit git hub library
BUGS
board choices
Buy at:
- DRobotics Online (UK)
output of compile/link conver to HEX is at :private/var/folders/f6/6ky0bfw11tg_0s27qw1yjgs00000gq/T/build6374132741676520612.tmp
/usr/local/CrossPack-AVR/bin/avr-objdump -j .sec1 -d -m avr5 sss.cpp.hex
dissasembler
JeremyBlum Arduino Tutorial-9-wireless-communication
simulavr