Skip to content

Instantly share code, notes, and snippets.

@electronut
electronut / atmega168-serial.c
Last active December 17, 2015 12:29
ATmega168 serial communications (transmit only) - most code is from the data sheet.
#define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1
void USART_Init(unsigned int ubrr)
{
/*Set baud rate */
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char)ubrr;
/*Enable receiver and transmitter */
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
@electronut
electronut / showdata.py
Created May 24, 2013 07:44
Display analog data from Arduino using Python (matplotlib)
################################################################################
# showdata.py
#
# Display analog data from Arduino using Python (matplotlib)
#
# electronut.in
#
################################################################################
import sys, serial
@electronut
electronut / analog-plot.ino
Created May 24, 2013 07:45
Read analog values from A0 and A1 and print them to serial port.
// analog-plot
//
// Read analog values from A0 and A1 and print them to serial port.
//
// electronut.in
#include "Arduino.h"
void setup()
{
@electronut
electronut / atmega168-power-save.c
Last active October 25, 2022 18:53
Putting the ATmega168 into Power Save mode, and then waking it with a pin-change interrupt.
//**********************************************************************
//
// Putting the ATmega168 into Power Save mode, and then waking it
// with a pin-change interrupt.
//
// electronut.in
//**********************************************************************
/*
build commands on OS X with CrossPack:
@electronut
electronut / HC-SR04-test.ino
Created May 28, 2013 12:54
Get distance information from Ultrasonic Ranging Module HC-SR04 and send it via serial port.
// HC-SR04-test.ino
//
// Get distance information from Ultrasonic Ranging Module HC-SR04 and
// send it via serial port.
//
// electronut.in
#include "Arduino.h"
int pinTrigger = 2;
@electronut
electronut / attiny84-hello.c
Created June 1, 2013 02:54
A simple program for the ATtiny84 that blinks an LED.
//
// A simple program for the ATtiny84 that blinks an LED.
//
// electronut.in
//
#include <avr/io.h>
#include <util/delay.h>
#define F_CPU 8000000
@electronut
electronut / Makefile
Created June 1, 2013 02:57
A simple program for the ATtiny84 that blinks an LED. Use Makefile with avr-gcc/avrdude.
# Name: Makefile
#
# A simple program for the ATtiny84 that blinks an LED.
#
# electronut.in
DEVICE = attiny84
CLOCK = 8000000
PROGRAMMER = -c usbtiny
OBJECTS = main.o
@electronut
electronut / attiny84-serial.c
Created June 3, 2013 11:50
Serials communications (TX only) with ATtiny84
//
// Serials communications (TX only) with ATtiny84
//
// electronut.in
//
#include <avr/io.h>
#include <string.h>
#include <util/delay.h>
#include <avr/interrupt.h>
@electronut
electronut / analogplot.py
Created June 7, 2013 15:34
Plot real-time analog data (single value) read from serial port using Python Matplotlib.
################################################################################
# showdata.py
#
# Display analog data from Arduino using Python (matplotlib)
#
# electronut.in
#
################################################################################
import sys, serial
@electronut
electronut / attiny84-hcsr04.c
Created June 7, 2013 15:37
Talking to ultrasonic sensor HC-SR04 with an ATtiny84, and sending distance data using serial communications.
//
// Talking to ultrasonic sensor HC-SR04 with an ATtiny84, and
// sending distance data using serial communications.
//
// electronut.in
//
#include <avr/io.h>
#include <string.h>
#include <util/delay.h>