Arduino Programming Cheat Sheet



C Programming For Beginners Master The C Language C Programming C Cheatsheet Inc C2011 Cheat Sh In 2020 Cheat Sheets Arduino Programming Computer Programming. Jquery Cheat Sheet Jquery Cheat Sheet Jquery Learn Web Development. C Programming For Beginners Master The C Language C Programming C Cheatsheet Inc C2011 Cheat Sh In 2020 Cheat Sheets Arduino Programming Computer Programming. This short post is a cheat sheet than you can use to check the ESP8266 NodeMCU pinout (V2 and V3 ESP8266 NodeMCU boards) for your Arduino IDE programs. For practical purposes ESP8266 NodeMCU V2 and V3 boards present identical pinouts. For our mechatronics projects we are mainly interested in the following pins: Power pins (3.3 V). Hey All, I've just made a single-page arduino cheat sheet! I've managed to cram in every function and syntax listed in the extended reference on one page, as well as some specs on common chips and pinouts.

Arduino Timer / PWM cheat sheet

Sheet

Arduino Timer

Arduino UNO (ATmega328p) has three 8bit timers

Timer0 - used for millis() micros() delay()… and is on pin 5, 6
Timer1 - 16bit timer is on pin 9, 10
Timer2 - 8bit timer is on pin 3, 11

Arduino Mega has six 8bit timers

Timer0 - millis, micros… and is on pin 4, 13
Timer1 - is on pin 11, 12
Timer2 - is on pin 9, 10
Timer3 - is on pin 2, 3, 5
Timer4 - is on pin 6, 7, 8
Timer5 - is on pin 46, 45, 44

Note: Don’t mess with Timer0 since we need to use millis() or micros() for measuring time

Software timer interrupt service routine

Arduino coding commands

Arduino UNO cannot do complex timer like a computer can. It heavily depends on frequency oscillator, ie 16MHz. Then we have divisor to scale down main clock and then 8bit counter to help with the PWM or Timer.

Arduino Programming Cheat Sheet

Arduino Programming Cheat Sheet In Pdf Format

There are 3 vectors for each timer that we can use to set up 3 ISRs

Setup Overflow vector ISR to use it like a timer in PC

Or we can use COMPARE VECTOR A and B which is compare to value of OCR2A , OCR2B

The only problem in phase-correct PWM (by default), the counter, e.g. TCNT2, goes from 0 to 255 and goes back from 255 to 0 then it overflows. So that each TIMER2_COMPA_vect and TIMER2_COMPB_vect happens twice when it is in Phase-correct PWM (default) but TIMER2_OVF_vect happens only once.

Anyway, we can set the value of counter TCNT2 manually to *mess* up time and thus changing timer or frequency, depends on what you want. But it is kinda messed up. You know, its hard to predict *butterfly*, if you’re watching too much movies about time travelling.

Cheat

Read datasheet of atmega328 to know how to set bits for TCCR2A, TCCR2B or TIMSK2 and so forth.


Arduino PWM

Arduino UNO (ATmega328p) has six 8bit PWMs (on 3 timers: timer0 - timer2)

Arduino Mega (ATmega2560) has fifteen 8bit PWMs (on six timers: timer0 - timer5)

Above are settings for Phase-corrected PWM (by arduino default).

analogWrite(PWMpin, value);

Default frequencies of analogWrite():

Arduino Pins 5 and 6: 976Hz
Arduino Pins 9, 10, 11, and 3: 490Hz

Too low for switch mode power supply (buck converter) and generate audible noise when use for motor or brushless fan (audible tone around 490Hz).

One trick is use the commands above (eg: TCCR1B = TCCR1B & B11111000 | B00000011;) after calling analogWrite() to change the default frequency.

You can double the frequency if we switch to fast PWM.

Otherwise, a custom analog output function should be used instead.

The input value (stored in OCRnA or OCRnB for first and second PWM pin) is compared against the value in an 8bit counter (0-255 and wrap around in register TCNTn).

If value <= counter, output HIGH
If value > counter, output LOW

In Phase-correct PWM mode

In Fast PWM mode

Arduino Cheat Sheet Pdf

Posted by ceez at 14:45:41