Babygnusbuino: Difference between revisions

From SGMK-SSAM-WIKI
Jump to navigation Jump to search
Line 171: Line 171:
/***
/***
babygnusbuino blink
babygnusbuino blink
note: PB0 circuit bent to pin 2
***/
***/


Line 184: Line 182:


volatile unsigned char e = 0;
volatile unsigned char e = 0;
volatile unsigned char BRGLed[3] = {0,0,0};
volatile unsigned char BRGLed[3] = {0,0,0};


void setup()
void setup()
{   
{   
  randomSeed(analogRead(0));
 
   // Timer Init
   // Timer Init
   cli();
   cli();
Line 201: Line 200:
   pinMode(LED1, OUTPUT);
   pinMode(LED1, OUTPUT);
   pinMode(LED2, OUTPUT);
   pinMode(LED2, OUTPUT);
 
}
}


void loop()
void loop()
{
{
  int r = random(0,255);
  int g = random(0,220);
  int b = random(0,220);
    
    
   for (int c = 0; c < 255; c++) {
   for (int a = 0; a < 60; a++) {  
     BRGLed[0] = c;
     delay(8000);
    BRGLed[1] = c;
     blend(r,g,b,a); // r g b alpha   
     BRGLed[2] = c;
    delay(1500);
   }
   }
}
/*
blend color
@param r Red
@param g Green
@param b Blue
@param da Alpha: the factor how much the new color will be blended with the existing color. da = 0: no change, da = 255: new color will be set (no blending).
*/
void blend(int r, int g, int b, int da) {
 
  // source alpha
  int sa = 255 - da;
 
  int tb = (sa * BRGLed[0] + da * b) + 128;
  int tr = (sa * BRGLed[1] + da * r) + 128;
  int tg = (sa * BRGLed[2] + da * g) + 128;
 
  BRGLed[0] = ((tb>>8)+tb)>>8;
  BRGLed[1] = ((tr>>8)+tr)>>8;
  BRGLed[2] = ((tg>>8)+tg)>>8;
    
    
}
}


//Overflow routine for Timer 1
// Overflow routine for Timer 1
ISR(TIM1_OVF_vect) {
ISR(TIM1_OVF_vect) {
   
   
Line 239: Line 260:
   e++;
   e++;
}
}


</syntaxhighlight>
</syntaxhighlight>

Revision as of 07:21, 27 December 2012

A ridiculously small Arduino with USB interface for bootloading and/or MIDI connection, based on the gnusb / Gnusbuino project.

Really bare-bones, no protection, no FTDI chip, single-sided PCB, no holes. The USB connector is directly etched on the board, so you actually plug in the PCB itself to upload a new sketch to the Arduino.

Attention This project is still work in progress - more of a proof of concept. I'm able to upload a blink sketch and it works, but there is some testing to be done. Hardware design could change - not sure if this is the best pin configuration - and the bootloader is a bit sketchy…

Building

Parts List

The only parts needed are:

  • 1 Atmel Attiny85 microprocessor
  • 2 resistors 68 Ohms
  • 2 zeners 3.3V
  • 1 resistor 1k6
  • 1 capacitor 100n

Circuit Schematic


PCB

File the board so that the brackets around the DIY USB connector are just barely visible, this should give the right fit.

Most PCB material is a little too thin, so this connector wiggles a lot inside the USB port - it's best to glue some cardboard or thin aluminum to the back of the board to make it slightly thicker.

Full SMD version

Scaled 400%

File:Babygnusbuino smd.pdf

DIL version

Scaled 400%, die löcher grad wegmachen oder.... ist ja pseudo-smd

File:Babygnusbuino dil.pdf

Programming

Source Code

The source code can be found in the SVN repository of the Gnusbuino [[1]]

Flashing the bootloader

The Bootloader is based on the USBasploader-tiny85 [[2]] - and of course on V-USB [[3]], the virtual USB driver from objective-development.

To get as small as possible, the board does not contain a ISP connector. We'd need it only once to flash the bootloader, anyway. From then on the chip can be reprogrammed directly trough USB. In order to flash the small outline smd chip, I made an adapter plate for the Gnusb-Prog (see: [[4]]) - where the chip is mounted temporarily and held in place with a paper clip:

File:Babygnusb programmer eagle.zip

File:Tiny prog smd.pdf

avrdude -P /dev/ttyUSB0 -b 19200 -c avrisp -p t85 -U lfuse:w:0xe1:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m

maybe change the devices on your OS

Avrdude issues

Unfortunately, the current ATTINY85 bootloader does not cope well with the speed at which it gets its data from avrdude, so the Arduino IDE does not work out of the box to program the Babygnusbuino. You'll have to compile a slower version of avrdude and replace the one that comes with Arduino (inside the Arduino Application).

(from my read me file:)

  • download avrdude source code here[[5]] (I was using 5.11)
  • replace the file usbasp.c with the one in variants/attiny85/avrdude patch
  • compile avrdude:
        ./configure
          make
  • replace the file /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avrdude with the newly compiled one

see also https://github.com/embedded-creations/USBaspLoader-tiny85/issues/1

Still, I sometimes have to try uploading three times until the "broken pipe" errors go away. Still work to do on this bootloader, guys…


Precompiled Binaries

Here is a patched version of avrdude - compiled for MacOS X 10.7. Nut sure if it works with other versions.

File:Avrdude tiny85 hack.zip


Here is a version of avrdude - compiled for Windows 7 x64

File:Avrdude-5.11-win7-x64-Gnusbuino-Hack.zip

A manual on how to compile avrdude for windows from source can be found here: http://tomeko.net/other/avrdude/building_avrdude.php (Note for the manual: in the libusb version 1.2.6.0 you have to rename "lusb0_usb.h" to "usb.h" so the avrdude source compiles fine.)

Uploading a sketch

When you plug in the Babygnusbuino it will first start into the bootloader and present itself as "USBasp" to the host computer. After about five seconds, if there's no activity, it will automatically start the main program. To upload a sketch:

  1. plug in Babygnusbuino
  2. within 2-3 seconds hit the "upload" button in Arduino

Sometimes I have to try several times - the timing is not always easy to get right. Also, bootloader is still a bit shaky, doesn't work every time. Be sure to read the results in the debug window.

Questions

  • what to do with the boards.txt file? (dusjagr)
    • Just leave it in .Documents/Arduino/hardware/Gnusbuino/
  • where to put stuff in linux? (avrdude is here: ./arduino-1.0.1/hardware/tools/)
    • I'd rename ./arduino-1.0.1/hardware/tools/avrdude to avrdude_bak or something, just in case. Then put new hacked avrdude at its place
  • what about the reset pin, aka PB5?
    • still no sure about that one. I wanted to leave it a reset so I can jump into bootloader without unplugging/replugging the thing. But on my board that doesn't seem to work, somehow. Otherwise you can set fuses to have it as a normal pin - but then you cannot reflash the bootloader anymore. As this project is pretty fresh (and the bootloader seems somewhat crappy, that doesn't seem to be very clever, for the moment).
    • Another Pin that could probably be freed up is PB0 - and tying D- through 1k6 directly to VCC. I needed this mechanism on the original gnusb for usb disconnecting and reconnecting but I'm not sure if it is really needed in this case. Will make some more research (don't disable RESET, yet ;-)
      • just hack the pins_arduino.h and add PB0 as Pin 2, and there you go. dont even need to change the resitor. we soldered the PD0 to the pads, where reset used to go
    • seems the easy logger just has a 2.2k resistor from vcc to D-....
  • can i send info/data to a computer? to use it in pd or similar software?
    • UPDATE: MIDI seems to work now on the Babygnusbuino, too. Use svn update to get the newest versionI'll try to adapt the Midignusbuino core for the Attiny85 as soon as I can. The first idea was to emulate a standard serial-class-device (CDC-Class) but apparently that could prove to be more difficult: "The back door to the low-speed bulk transfer is gradually closing on the newer OS. After enjoying this USB technology, switch to the HID protocol or to MCU having on-chip USB controller." [6] (mirdej)
    • MIDI works super for PD

  • I choose the Babygnusbuino in the arduino /Tools/Board but which programmer?
    • no need to chose a programmer - the boards.txt file defines USBasp as the programmer
  • can i burn the bootloader from the Arduino IDE, with eg. Arduino-ISP? using an ISP connection?
    • should work (before soldering the chip on board)
  • on what internal clock is the Attiny85? 1MHZ? 8MHZ?
    • 16.5 Mhz internal PLL, calibrated to +/- 1% by listening to USB packets
    • avrdude -P /dev/ttyUSB0 -b 19200 -c avrisp -p t85 -U lfuse:w:0xe1:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m (something like this?)
      • exactly the fuses I used, too: -U lfuse:w:0xe1:m -U hfuse:w:0xdd:m-U efuse:w:0xfe:m
  • my arduino IDE doesnt see the USBasp
    • check your soldering and make sure u had the right parts
    • timing when you plug in your Baby..

Installing it on ubuntu 12.04/linux (dusjagr)

  • download the gnusbuino folder from here: http://gnusb.svn.sourceforge.net/viewvc/gnusb/branches/gnusbuino/
  • copy the folder ./gnusbuino/hardware/Gnusbuino into your personal arduino folder ~/sketchbook/hardware/* create the hardware folder yourself if needed.
  • make the avrdude as described above
    • had to install: (in addition to many things already there)
      • bison
      • flex
      • libusb-devel
    • and remove:
      • byacc-j
  • copy avrdude into folder ./arduino-1.0.1/hardware/tools
  • device showed up with "lsusb" as: Bus 001 Device 007: ID 16c0:05dc VOTI shared ID for use with libusb
  • had to change "only root access" for usbasp as described here:
    • The fix: Create a file called 10-usbtinyisp.rules in directory /etc/udev/rules.d
# USBtinyISP Programmer rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c9f", GROUP="adm", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="0479", GROUP="adm", MODE="0666"
# USBasp babygnuspuino Programmer rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05dc", GROUP="adm", MODE="0666"
    • Then execute:
sudo restart udev

other stuff

der frickelt auch mit ner spezial version von arduino.... http://www.kickstarter.com/projects/digistump/digispark-the-tiny-arduino-enabled-usb-dev-board/posts/350928

Example Code

we got some pseudo PWM working using interupts... see example below. but the delay is wrong, something has to be fixed with the timers...

RGB Led

/***
babygnusbuino blink
***/

#include <avr/io.h> 
#include <avr/interrupt.h> 
#include <util/delay.h>

int LED0 = 0; // Blue
int LED1 = 1; // Red
int LED2 = 2; // Green

volatile unsigned char e = 0;
volatile unsigned char BRGLed[3] = {0,0,0};

void setup()
{  
  randomSeed(analogRead(0));
  
  // Timer Init
  cli();
  
  TCCR0A = 0x00;
  TCCR0B = 0x01;
  TIMSK = (1 << TOIE1); // Overflow 
  
  sei();
  
  pinMode(LED0, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
}

void loop()
{
  int r = random(0,255);
  int g = random(0,220);
  int b = random(0,220);
  
  for (int a = 0; a < 60; a++) { 
    delay(8000);
    blend(r,g,b,a); // r g b alpha    
  }
}


/*
blend color
@param r Red
@param g Green
@param b Blue
@param da Alpha: the factor how much the new color will be blended with the existing color. da = 0: no change, da = 255: new color will be set (no blending).
*/
void blend(int r, int g, int b, int da) {
  
  // source alpha
  int sa = 255 - da;
  
  int tb = (sa * BRGLed[0] + da * b) + 128;
  int tr = (sa * BRGLed[1] + da * r) + 128;
  int tg = (sa * BRGLed[2] + da * g) + 128;
  
  BRGLed[0] = ((tb>>8)+tb)>>8;
  BRGLed[1] = ((tr>>8)+tr)>>8;
  BRGLed[2] = ((tg>>8)+tg)>>8;
  
}

// Overflow routine for Timer 1
ISR(TIM1_OVF_vect) {
 
  if(e==255) {
     e=0;
     digitalWrite(LED0, HIGH);
     digitalWrite(LED1, HIGH);
     digitalWrite(LED2, HIGH);
    }
 
  if (BRGLed[0] == e) {  
     digitalWrite(LED0, LOW);
  }
 
  if (BRGLed[1] == e) {  
     digitalWrite(LED1, LOW);
  }
 
  if (BRGLed[2] == e) {  
     digitalWrite(LED2, LOW);
  }
  e++;
}

RGB Led spectrum

/***
babygnusbuino RGB Spectral Sweep
 
note: PB0 circuit bent to pin 2, formmely connected to reset
***/
 
#include <avr/io.h> 
#include <avr/interrupt.h> 
#include <util/delay.h>
 
int LED0 = 0; // Blue
int LED1 = 1; // Red
int LED2 = 2; // Green

int wait = 10000;

unsigned char sensorValue = 0;        //8bit 
volatile unsigned char e = 0;
volatile unsigned char BRGLed[3] = {0,0,0};
 
void setup()
{  
  // Timer Init
   
  TCCR0A = 0x00;
  TCCR0B = 0x01;
  TIMSK = (1 << TOIE1); // Overflow 
 
  sei();
 
  // Set pins
 
  pinMode(LED0, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
 
}
 
void loop()
{
 
  for (int c = 0; c < 255; c++) {
  
    sensorValue = c;
    
    if (sensorValue < 43) { 
 
   BRGLed [0] = (255); //red
   BRGLed [1] = (sensorValue*6); //green
   BRGLed [2] = (0); //blue
    }
 
   else if (sensorValue < 85) { 
 
   BRGLed [0] = (255-(sensorValue-43)*6); //red
   BRGLed [1] = (255); //green
   BRGLed [2] = (0); //blue
    }
 
   else if (sensorValue < 127) { 
 
   BRGLed [0] = (0); //red
   BRGLed [1] = (255); //green
   BRGLed [2] = ((sensorValue-85)*6); //blue
    }
 
     else if (sensorValue < 169) { 
 
   BRGLed [0] = (0); //red
   BRGLed [1] = (255-(sensorValue-127)*6); //green
   BRGLed [2] = (255); //blue
    }
 
   else if (sensorValue < 211) { 
 
   BRGLed [0] = ((sensorValue-169)*6); //red
   BRGLed [1] = (0); //green
   BRGLed [2] = (255); //blue
    }
 
   else if (sensorValue < 253) { 
 
   BRGLed [0] = (255); //red
   BRGLed [1] = (0); //green
   BRGLed [2] = (255-(sensorValue-211)*6); //blue
    }
 
  else { 
 
   BRGLed [0] = (255); //red
   BRGLed [1] = (0); //green
   BRGLed [2] = (0); //blue
    }
 
  delay (wait);
 
  }
 
}
 
//Overflow routine for Timer 1
ISR(TIM1_OVF_vect) {
 
  if(e==255) {
     e=0;
     digitalWrite(LED0, HIGH);
     digitalWrite(LED1, HIGH);
     digitalWrite(LED2, HIGH);
    }
 
  if (BRGLed[0] == e) {  
     digitalWrite(LED0, LOW);
  }
 
  if (BRGLed[1] == e) {  
     digitalWrite(LED1, LOW);
  }
 
  if (BRGLed[2] == e) {  
     digitalWrite(LED2, LOW);
  }
  e++;
}