Skip to content

Instantly share code, notes, and snippets.

@electronut
electronut / atmega168-serial.c
Last active Dec 17, 2015
ATmega168 serial communications (transmit only) - most code is from the data sheet.
View atmega168-serial.c
#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
Display analog data from Arduino using Python (matplotlib)
View showdata.py
################################################################################
# showdata.py
#
# Display analog data from Arduino using Python (matplotlib)
#
# electronut.in
#
################################################################################
import sys, serial
@electronut
electronut / analog-plot.ino
Created May 24, 2013
Read analog values from A0 and A1 and print them to serial port.
View analog-plot.ino
// 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 May 28, 2018
Putting the ATmega168 into Power Save mode, and then waking it with a pin-change interrupt.
View atmega168-power-save.c
//**********************************************************************
//
// 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
Get distance information from Ultrasonic Ranging Module HC-SR04 and send it via serial port.
View HC-SR04-test.ino
// 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 Jun 1, 2013
A simple program for the ATtiny84 that blinks an LED.
View attiny84-hello.c
//
// 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 Jun 1, 2013
A simple program for the ATtiny84 that blinks an LED. Use Makefile with avr-gcc/avrdude.
View Makefile
# 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 Jun 3, 2013
Serials communications (TX only) with ATtiny84
View attiny84-serial.c
//
// 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 Jun 7, 2013
Plot real-time analog data (single value) read from serial port using Python Matplotlib.
View analogplot.py
################################################################################
# showdata.py
#
# Display analog data from Arduino using Python (matplotlib)
#
# electronut.in
#
################################################################################
import sys, serial
@electronut
electronut / attiny84-hcsr04.c
Created Jun 7, 2013
Talking to ultrasonic sensor HC-SR04 with an ATtiny84, and sending distance data using serial communications.
View attiny84-hcsr04.c
//
// 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>
You can’t perform that action at this time.