SGMKtiny

From SGMK-SSAM-WIKI
Jump to: navigation, search

SGMKtinyuoino v03.jpg

easy to use on breadboards with onboard connected ISP port. see general info about Hands On AVR

Pin Layout

v0.6:

Tinyuino6.png

ATtiny45-85.png


v0.5

Tinyuino5 labels.png

Another proposal for the SPI connector

Personally I find the "standard" AVR 6pin ISP connector very cumbersome

  • not easy to route around it
  • very small pads
  • difficult to remember what pin is what
  • without the correct cable with molex connector you're fucked

So I started to design all my boards that need a ISP connector like this:

Simple isp.png

GND | VCC | RESET | SCK | MISO | MOSI all in one row.

The advantage is that it's the same pinout like the bigger ATMEGAs, where you can pull out the ISP just straight like this: gnusb-procreation

Mask

Programming the SGMKtiny

USBtiny problems

if you have the USBtiny programmer the device is only accesible by root (solution found here: http://mightyohm.com/blog/2010/03/run-avrdude-without-root-privs-in-ubuntu )

The fix:

Create a file called 10-usbtinyisp.rules in directory /etc/udev/rules.d

SUBSYSTEM=="usb", SYSFS{idVendor}=="1781", SYSFS{idProduct}=="0c9f", GROUP="adm", MODE="0666"

Then execute:

sudo restart udev

That’s it. Unplug and replug in the USB cable to your USBTinyISP programmer. Now avrdude should be able to access the USBTinyISP without root privileges.

If your account is part of another group, just change the GROUP= flag to that group instead. New users in Ubuntu are assigned to a group named after their username by default, so that is another option (ie. GROUP=”yourusername”). Interestingly, new users are not assigned to the “users” group, for reasons that escape me (and no doubt some of our more Linux-savvy readers can enlighten us about).

Hardcore AVR programming

see general info about Hands On AVR

CrossPack development environment for Atmel’s AVR® microcontrollers running on Apple’s Mac OS X

programming with the Arduino IDE

programming the attiny85 with the arduino IDE


I2C stuff

TinyWire on Arduino playground

Code Examples

Random noise generator

first set the clock divider to 8MHz

clock divided by 8 (1Mhz, as delivered) -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m

clock not divided (8Mhz) avrdude -b 19200 -c usbtiny -p t85 -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m

/* Pseudo-Random Bit Sequence Generator                     2009-11-25 */
/* Copyright (c) 2009 John Honniball, Dorkbot Bristol                  */
 
/*
 * For a discussion of PRBS generators, see The Art Of Electronics, by
 * Horowitz and Hill, Second Edition, pages 655 to 660. For more info
 * on Linear Feedback Shift Registers, see Wikipedia:
 *   http://en.wikipedia.org/wiki/Linear_feedback_shift_register
 * For the actual shift register taps, refer to this article on noise
 * generation for synthesisers:
 *   http://www.electricdruid.net/index.php?page=techniques.practicalLFSRs
 */
 
// Choose the same pin as the "Melody" example sketch
int speakerPin = 0;
 
int potiPin = 1;
 
unsigned int analogValue;
 
int samplingDelay;
 
unsigned long int reg;
 
void setup ()
{
  // Serial setup for debugging only; slows down the program far too much
  // for audible white noise
  //Serial.begin (9600);
 
  // Connect a piezo sounder between Ground and this pin
  pinMode (speakerPin, OUTPUT);
 
 
  // Arbitrary inital value; must not be zero
  reg = 0x551155aaL;
}
 
 
void loop ()
{
  unsigned long int newr;
  unsigned char lobit;
  unsigned char b31, b29, b25, b24;
 
  // Extract four chosen bits from the 32-bit register
  b31 = (reg & (1L << 31)) >> 31;
  b29 = (reg & (1L << 29)) >> 29;
  b25 = (reg & (1L << 25)) >> 25;
  b24 = (reg & (1L << 24)) >> 24;
 
  // EXOR the four bits together
  lobit = b31 ^ b29 ^ b25 ^ b24;
 
  // Shift and incorporate new bit at bit position 0
  newr = (reg << 1) | lobit;
 
  // Replace register with new value
  reg = newr;
 
  // Drive speaker pin from bit 0 of 'reg'
  digitalWrite (speakerPin, reg & 1);
 
  // Display 'reg' in the serial console for debugging only 
//  Serial.println (reg, HEX);
  samplingDelay = 1 + (2*(analogRead(potiPin)>>0));
  // Delay corresponds to 20kHz, but the actual frequency of updates
  // will be lower, due to computation time and loop overhead
  delayMicroseconds (samplingDelay);
 
  // If the above delay is increased to a few tens of milliseconds,
  // and the piezo sounder is replaced by an LED and a suitable series
  // resistor, a randomly flashing light will result. Several LEDs
  // could be driven from various bits of the shift register.
}
 
 
from [http://tziteras.blogspot.com/2009/11/green-noise-experiment.html John Honnibal]


Software Serial works on an ATiny85

important configure the ATiny85 to run on 8Mhz

avrdude -b 19200 -c usbtiny -p t85 -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m 
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// on the SGMKtiny there is usually a led connected to pin 0
// give it a name:
int led = 0;
 
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}
 
// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}


Software Serial ATiny85 to serialLCD

SoftSER tiny.jpg

Software Serial to talk with pd

Code for Arduino

/*
  Software serial multple serial test
 
 The circuit: not sure with attiny, what is rx and what tx...
 * RX is digital pin 1 (connect to TX of other device)
 * TX is digital pin 0 (connect to RX of other device)
 
 Note:
 Not all pins on the attiny85 support change interrupts, 
 so only the following can be used for RX/TX: 
 0, 1
 
 This example code is in the public domain.
 
 */
 
#include <SoftwareSerial.h>
 
int sensorPin = 1; // select the analog input pin for the potentiometer ADC1 = PB2
int sensorValue = 0;  // variable to store the value coming from the sensor
 
 
SoftwareSerial mySerial(0, 1); // RX, TX
 
void setup()  
{
  // Open serial communications and wait for port to open:
 
  // set the data rate for the SoftwareSerial port
  mySerial.begin(38400);
  mySerial.println("Hello, world?");
}
 
void loop() // run over and over
{
 
  sensorValue = analogRead(sensorPin); 
 
  mySerial.print("T ");
  mySerial.print((sensorValue), DEC);
  mySerial.println();
  delay(2);
 
  /* this is kinda serial echo to check if it can receive... not yet tested in detail
 
  if (mySerial.available())
    mySerial.write(mySerial.read());
 
  */
}

pd patch

download: File:SGMKtiny 2 pd-logger.zip

the serial port in pd needs to be changed according to your OS and serial interface

Attiny 2 pd logger.png


Demo: SoftwareSerial: ATtiny85 speaks to Arduino/TVout

Software Serial on ATtiny85 (YouTube)

SoftwareSerial On ATtiny85.jpg

Remark: This example is based on the TVout library for Arduino and demonstrates the possibility to use serial communication between different devices.

Arduino source code:

#include <TVout.h>
#include <pollserial.h>
#include <fontALL.h>
 
#define CLAMP(x, l, h)  (((x) > (h)) ? (h) : (((x) < (l)) ? (l) : (x)))
 
static const float R_MAX = 500.0f;
 
TVout TV;
pollserial pserial;
 
void setup()
{
  TV.begin( PAL, 120, 96 );
  TV.select_font( font6x8 );
  TV.set_hbi_hook( pserial.begin( 38400 ) );
}
 
static uint8_t index = 0; 
static char buffer[100] = { '\0' };
void loop()
{
  if( pserial.available() )
  {
    char c = (char)pserial.read();
 
    buffer[index] = c;
    ++index;
 
    if( c == '\n' )
    {
      buffer[index] = '\0';
      index = 0;
 
      int value = 0;
      sscanf( buffer, "%i", &value );
 
      float radius = (float)( value / R_MAX );
      radius = CLAMP( radius, 0.0f, R_MAX );
      int r = (int)( radius * (float)TV.vres() * 0.5f );
 
      // print radius as text
      //TV.println( (double)radius );
 
      // draw circle
      TV.clear_screen();
      TV.draw_circle( TV.hres()/2, TV.vres()/2, r, WHITE );
    }
  }
}


Arduino project: File:TVout SerialMonitor0.zip