Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Sunday, 2 June 2019

ATTiny EEPROM usage


Tutorial: Using EEPROM on the ATTiny Series of microcontrollers

 
ATTiny EEPROM Tutroial

Intro

This is the first tutorial by Barium Electronics that will be dealing with using the internal EEPROM of an ATTiny using the Arduino IDE and also using the AVR EEPROM library.

The Arduino EEPROM library is compatible with the ATTiny range of AVR microcontrollers as the library itself is built on the standard Atmel AVR avr/eeprom.h 'library' so it is compatible with all the AVR microcontrollers.

This was originally written back in 2016 (wow...) so some things may not match what people have floating around now :)

Things needed:

  • ATTiny of your choice, I prefer the t85
  • ISP programmer/ArduinoISP (Pocket ISP, USBasp)
  • Breadboard
  • Cup of coffee

Friday, 31 July 2015

Weather Station - Anemometer

Copyright


























So I have been working on the anemometer on and off for the last month as I have also been working on another project. I have also been working on the final design of the weather vane setup and slicing my thumb :) This will be part one of this part of the weather station, discussing mainly the anemometer.

The basic build

Sunday, 19 April 2015

Weather Station - Rain Gauge

tipping bucket arduino
For the first build post I will be starting with the rain gauge. This is based off the tipping bucket rain gauge method. These are pretty easy to make and get running.

Monday, 15 December 2014

Tiny Bot

This has probably been done to death on the blogs but I was inspired by the born 2 craft site. Mine needs a bit of work in the code but I generally prefer to do something from scratch by myself after seeing an idea. Mine is also a bit larger as it is veroboard.


attiny85 robot

Design


The parts are all hacked off of other dead RC toys and boards, ATTiny85 is the only thing I paid for, makes me happy. The system uses a small LiPo striped from crashed mini RC helicopter, nice and light. The board layout was worked out in building, working around the socket as it was meant to be a 8 pin PIC proto-board. 

The wheels were made from ABS sheet, using a circle template at 23mm. Using the four centre marks on the diameter I drew between opposite ones to get the point to make a hole for the shaft, I used a dividers point and checked every now and then to see the fit, just push on with reasonable pressure. 
I used marine silicon to create a tread. This is done by running two strips along ABS sheet at the distance of the wheels, and roll back and forth.

The battery is charged by a full spec LiPo balance charger through the headers, the switch is moved towards the header toput in charge mode.


Some build pics, some:



Underside

Front View

Hardware

The design of the circuit is similar to the born 2 craft, but I made some modifications.
I added the flyback diodes to the two motors, I skimped on those to begin with as there was not enough space, but after changing the transistors for both motors I added them. The PCB layout is my design.


  • Transistors are BC817-40
  • Diodes are 1N4148
  • ATtiny85/45
  • Small model motors
  • 0805 resistors
  • LiPo 3.7v
  • Switch SPST
  • Wheels: ABS, 23mm dia.
  • Some copper wire, varying thickness
Schematic
PCB

Code


/*
Tiny Bot: an LDR based light following robot, or avoidance bot
 if you switch the drive function around.
 Hardware is based off the Light Bot by born 2 craft

 TODO:
 Add IR control
 Clean up code
 ##############################
 Written by:
 Reece May 
 rev1 12/15/14
 https://ziggyelectronics.blogspot.com

You may use the code and modify it as long as you keep the above
and make edit notes bellow and put it on github here:
https://github.com/ReeceM/Tiny-Bot.git
 */

#define Rmtr 1
#define Lmtr 0
#define Rsens 3
#define Lsens 2
#define drive_time 100

int Rav, Lav = 0;

void setup(){

  pinMode(Rmtr, OUTPUT); 
  pinMode(Lmtr, OUTPUT);
  pinMode(Rsens, INPUT);
  pinMode(Lsens, INPUT);

}

void ADread(){
  Rav, Lav = 0;   //clear the average to prevent errors

  for(int q = 0; q < 20; q++){ //loop to create average

    Rav += analogRead(Rsens);
    Lav += analogRead(Lsens);
  }

  Rav /= 19;
  Lav /= 19;
}

void drive_RIGHT(){
  digitalWrite(Lmtr, 0);

  digitalWrite(Rmtr, 1);
  delay(drive_time);
  digitalWrite(Rmtr, 0);
  delay(drive_time);
}

void drive_LEFT(){
  digitalWrite(Rmtr, 0);

  digitalWrite(Lmtr, 1);
  delay(drive_time);
  digitalWrite(Lmtr, 0);
  delay(drive_time);
}

void loop(){

  ADread();
  if(Rav < Lav){
    drive_RIGHT();
    //drive_LEFT();  //use this to avoid light
  }
  ADread();
  if(Lav < Rav){
    drive_LEFT();
    //drive_RIGHT();  //use this to avoid light
  }
}

Links

https://github.com/ReeceM/Tiny-Bot.git