Monday 17 November 2014

ATTiny85 – Tutorial 11 – Light Input Controlling Sound Output

This is the final Freetronics 11 – Experimenters Kit tutorial. The other 10 tutorials have been covered and, I’m please to say, I have now completed all 11 tutorials with the ATTiny85.

This tutorial makes use of the Freetronics Light module (a light detecting resistor or LDR) with the Freetronics Sound module (a piezo electric module). The light level is read by the analog LDR and the light level value is passed as a tone to the piezo.

Once again, we are using a web sourced tone function that makes use of the ATTiny85 timers to produce an output tone value. This time, however, we are not using predefined wave cycle values, but using analog light level values to drive the tone.

ATTiny85 Pin - Lesson 11

The Piezo is connected on pin 1 (ATTiny85 pin 6), while the LDR is connected on A2 (ATTiny85 pin 3).

Tutorial11

The LDR also connects VCC to the positive rail and GND to the negative rail.

The modified sketch:

/* Tutorial 11: Light Input Controlling Sound Output */

int piezo = 1;
int lightLevel = 0;
int duration = 300;

void setup()
{
  pinMode(piezo, OUTPUT);
}

void loop()
{
  lightLevel = analogRead(A2);
  TinyTone(lightLevel, 4, duration);
}

void TinyTone(unsigned char divisor, unsigned char octave, unsigned long duration)
{
  TCCR1 = 0x90 | (8-octave); // for 1MHz clock
  OCR1C = divisor-1;         // set the OCR
  delay(duration);
  TCCR1 = 0x90;              // stop the counter

}

I believe that TCCR1 and OCR1C both point to pin 1 (but I’d have to research that a little to make sure). Reason tells me that this is so … reason and I are not always particularly good friends.

It would be nice to reduce the delay so that the tones are more smooth, it would be kinda like a light driven theramin.

Check out the rest of the tutorials here.

Friday 14 November 2014

AVRDUDE – Pagel and BS2 error

According to Wiki, the Pagel BS2 signals error that happens when you are programming an ATTiny85 (and apparently the 84 too) is a consequence of some missing configuration in the avrdude.conf file that comes with the Arduino.
Apparently, you need to correct the configuration problems and then everything will be fine. It is.
  1. Go to your Arduino IDE installation folder (something like C:\Program Files (x86)\arduino-1.0.4\hardware\tools\avr\etc.
  2. Before you do anything … make a backup of the file avrdude.conf
  3. Open the avrdude.conf file in a text editor
  4. locate the ATTiny85 section in the file
  5. locate the chip_erase_delay = 4500; line
  6. add the following two lines below this:
      pagel = 0xB3;
      bs2 = 0xB4;
  7. locate the memory=”lock” keyword in the ATTiny85 section
  8. replace this section with the following (copy and paste)
memory "lock"
   size  = 1;
   write = "1 0 1 0  1 1 0 0  1 1 1 x  x x x x",
           "x x x x  x x x x  1 1 i i  i i i i";
   read  = "0 1 0 1  1 0 0 0  0 0 0 0  0 0 0 0",
           "0 0 0 0  0 0 0 0  o o o o  o o o o";
   min_write_delay = 9000;
   max_write_delay = 9000;
;


Do the same for the ATTiny84 section.
You will need to restart the IDE for this to be affected.
After this, you need to
  1. Connect the ATTiny85 to the Arduino using your favourite ICSP
  2. load the sketch into the IDE
  3. Select the ATTiny85 board in the IDE
  4. Select Arduino as ISP in the IDE
  5. Upload your sketch to the ATTiny85.
That should fix the problem.
I have now tested the abovementioned fix and the error message has now gone away. To test this, I loaded the sketch from Tutorial 10, compiled and then uploaded it to the ATTiny85 with the following, successful, result.
image
As you can see, the Pagel and BS2 error messages have gone … YAY! Thank you Wiki Page!
After uploading the sketch to the ATTiny85, I dropped the ATTiny85 chip into the circuit and powered it up, again, success. The circuit does what it’s supposed to do.
All in all, happy camper time.

Thursday 13 November 2014

ATTiny85 – Tutorial 10 – Detecting Knocks and Vibration

This tutorial in it’s original form sends the detection of knocks and vibrations from the Freetronics ”Sound” module to the serial monitor. As we don’t have access to a serial monitor from the ATTiny85, instead we are going straight to the extended tutorial, monitoring our knocks and vibrations with an LED.

ATTiny85 Pin Project 10

For this tutorial, the Piezo (Sound module) is connected on A1 (ATTiny85 pin 7) and an LED is connected to 0 (ATTiny85 pin 5).

The Piezo is read using the analogRead Arduino function and, when the analog value read from the Piezo is > 5, it will light up our LED (with a pull down resistor).

/* Project 10: Detecting Vibrations and Knocks */

int knock = 0;

void setup()
{
  pinMode(0, OUTPUT);
}

void loop()
{
  knock = analogRead(A1);
  if(knock>5)
  {
    digitalWrite(0, HIGH);
    delay(300);
    digitalWrite(0, LOW);
  }
}

The sketch is pretty straight forward … the variable knock is assigned the value of analogRead and, if it’s value is > 5 the ATTiny85 turns the LED on with digitalWrite, then waits 300 milliseconds, and then turns the LED off again with digitalWrite.

Tutorial10

You can see from the above image that the wiring is pretty straight forward. Top right of the breadboard is  the 5V regulator. The ATTiny85 was programmed using the ATTiny85 ICSP.

ATTiny85–Detecting Knocks and Vibrations with Freetronics “Sound” module

This is the 10th Freetronics Experimenters Kit tutorial that I’ve converted to the ATTiny85.

Check out the rest of the tutorials here.

Thursday 6 November 2014

ATTiny85 – Tutorial 9 – Making Sounds

While this looked like a fairly simple tutorial on the face of it, it was actually a bit more difficult.

The main problem that I encountered was that the tone() function is not supported by the ATTiny85 core, so I had to do a bit of hunting around to find an equivalent method for the ATTiny85. As I expected, others had come across this same problem and had already developed a solution for it.

Two of the solutions that I tried (arduino-tiny library and a beep function) were both unsuccessful. Both produced cricket sounds (probably because the timing was wrong). However, I found Simple Tones for ATtiny that produces a nice scale and didn’t cause me too many other problems.

ATTiny85 - Tutorial 09

The connection from the ATTiny85 to the Piezo is very simple. Connect Pin 1 of the ATTiny85 to either pin of the piezo (it isn’t polarised). Connect GND to the other pin of the piezo.

Here is the sketch from the Technoblogy article referred to above (Simple Tones for ATTiny).

/* TinyTone for ATtiny85 */

// Notes
const int Note_C  = 239;
const int Note_CS = 225;
const int Note_D  = 213;
const int Note_DS = 201;
const int Note_E  = 190;
const int Note_F  = 179;
const int Note_FS = 169;
const int Note_G  = 159;
const int Note_GS = 150;
const int Note_A  = 142;
const int Note_AS = 134;
const int Note_B  = 127;

int Speaker = 1;

void setup()
{
  pinMode(Speaker, OUTPUT);
}

void loop()
{
  playTune();
  delay(300);
}

void TinyTone(unsigned char divisor, unsigned char octave, unsigned long duration)
{
  TCCR1 = 0x90 | (8-octave); // for 1MHz clock
  // TCCR1 = 0x90 | (11-octave); // for 8MHz clock
  OCR1C = divisor-1;         // set the OCR
  delay(duration);
  TCCR1 = 0x90;              // stop the counter
}

// Play a scale
void playTune(void)
{
TinyTone(Note_C, 4, 500);
TinyTone(Note_D, 4, 500);
TinyTone(Note_E, 4, 500);
TinyTone(Note_F, 4, 500);
TinyTone(Note_G, 4, 500);
TinyTone(Note_A, 4, 500);
TinyTone(Note_B, 4, 500);
TinyTone(Note_C, 5, 500);
}

This sketch works just dandy, straight out of the box. Nice work Technoblogy, nice work indeed.

I need to do some more research to find out how I can get the tone() function from the arduino-tiny library to work satisfactorily, but for now, the above sketch serves my purpose.

Making Sounds with Piezo and the ATTiny85

Well, that concludes Tutorial 9. Enjoy. Once again, 9V to 5V Regulator and ATTiny85 ICSP were used to make this tutorial circuit.

Check out the rest of the tutorials here.

Tuesday 4 November 2014

ATTiny85 – Tutorial 6 – Making Things Move With Servos

The Freetronics Tutorial 6 replaces the LED and Resistor connection on pin 11 of the Freetronics 11 with the data connection to a simple servo.

The ATTiny85 version does the same thing … not really much sense reinventing the wheel, huh?

ATTiny85 - Lesson 6 - Making Things Move With Servos

As we learn with Tutorial 7, there are three PWM pins on the ATTiny85 to choose from. I went with the easiest and most convenient … our old friend, pin 0.

If you use the sketch from Tutorial 5 in the Freetronics Tutorial with a servo instead of an LED, then this sketch works admirably.

// Tutorial 6: Making things move with servos
int led = 0;
int brightness = 0;
int delayTime = 10;

void setup()
{
  pinMode(led, OUTPUT);
}

void loop()
{
  while(brightness < 255)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness++;
  }
  while(brightness > 0)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness--;
  }
}
 

Of course, I’m using the ++ and – incrementing function rather than brightness = brightness + 1; and brightness = brightness –1; because I think that it looks better, but that’s just me. Let the spirit guide you in your decision …

Lesson 6 - Running

The green jumper connects from ATTiny85 pin 0 to the yellow connector on the servo, Red connects to Orange on the Servo from the 5V rail and the black jumper connects the brown servo connection to GND.

Here’s a short video of the action.

ATTiny85 Controlling a servo with PWM

Check out the rest of the tutorials here.

Monday 3 November 2014

ATTiny85 – Tutorial 7 – RGB LED

I was playing around looking at the information at hand on the ATTiny85 PWM and I thought that there were only 2 PWM capable pins on the chip … apparently, I was wrong, there are three. PB0, PB1 and PB2 are all PWM. Until I realised that, I was toying with the idea of software based PWM. There are some pretty good articles, tutorials and pages relating to software PWM, so I’ll probably get around to playing with it, some other time.

In the meantime. I had another look over the Freetronics Tutorial #7 – RGB LED and I decided that the code was a little clunky. The RGB values all jump to their random values and there is a lot of blinking … that’s OK if that’s what you want. Anyway, I had a quick play and decided to make the values rise from 0 to their random value and then back down to 0 so that they fade in and out. It’s still a little inelegant, but for the sake of a decent tutorial, I thought that this would be fairly useful.

ATTiny85 - Lesson 7 - RGB LED

My code is as follows

//Tutorial 7: RGB LED *** EXTENDED

int rPin = 0;
int gPin = 1;
int bPin = 2;

void setup()
{
  pinMode(rPin, OUTPUT);
  pinMode(gPin, OUTPUT);
  pinMode(bPin, OUTPUT);
  analogWrite(bPin, random(0, 255));
  analogWrite(gPin, random(0, 255));
  analogWrite(rPin, random(0, 255));
  delay(500);
}

void loop()
{
  upDown(random(0,255), random(0,255), random(0,255));
  delay(500);
}

void upDown(int r, int g, int b)
{
  //bring the colours up
  int rVal, gVal, bVal = 0;
  for(int rVal = 0; rVal < r; rVal++)
  {
    analogWrite(rPin, rVal);
    delay(10);
  }
  for(int gVal = 0; gVal < g; gVal++)
  {
    analogWrite(gPin, gVal);
    delay(10);
  }
  for(int bVal = 0; bVal < b; bVal++)
  {
    analogWrite(bPin, bVal);
    delay(10);
  } 
 
//  return to 0
  while(rVal>0)
  {
    rVal--;
    analogWrite(rPin, rVal);
  }
 
    while(gVal>0)
  {
    gVal--;
    analogWrite(gPin, gVal);
  }
 
    while(bVal>0)
  {
    bVal--;
    analogWrite(bPin, bVal);
  }
 
}

This is still fairly close to the original, with an upDown function that fades each colour in and then all of them out again.

I used my ATTiny85 ICSP to program the ATTiny85 and the 9V to 5V power regulator to supply the solderless bread board.

Lesson 7 - Board

As you can see, there isn’t anything outside of the Arduino core being used in the code, and the wiring is very straight forward. The layout is as per the Freetronics tutorial (more or less … I’ve added a jumper from the top to bottom rails).

Here is how it looks when it’s running. Bear in mind that the cycle uses a random RGB value and splits it up, so it *should* be different for every cycle.

RGB LED Controlled by PWM on the ATTiny85

Well … it’s now well past my bed-time, so I’m calling it a night.

Have fun ATTiny85ers!

Check out the rest of the tutorials here.

ATTiny85 – Tutorial 5 – Dimming LED using PWM

This tutorial is a very simple conversion from ATMEGA328P to ATTiny85, there is only one pin involved in producing output, so we only need to change from pin 11 to pin 0. On the ATTiny85, there are three hardware PWM pins … pin 0, pin 1 and pin2 , so it’s simply a matter of switching over to Pin 0 and away we go.

ATTiny85 - Lesson 5 - Dimming LED with PWM

I’ve changed the sketch for personal taste (and I think, efficiency), you’re free to use the Freetronics version of the code if you like … it’s no great shakes on something this small.

/* project 5: Controlling LED brightness with PWM */

int led = 0;
int brightness = 0;
int delayTime = 10;

void setup()
{
  pinMode(led, OUTPUT);
}

void loop()
{
  while (brightness < 255)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness++;
  }
  while (brightness > 0)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness--;
  }
}

As you will see from the following image, there isn’t much to the wiring for this project.

Tutorial5

And here’s the circuit running through it’s light/dim wizardry.

Tutorial 5 – ATTiny85 - Dimming LED with PWM

Once again, I’m using my ATTiny85 ICSP to program the ATTiny85 using the Arduino UNO and my 9V to 5V power regulator to supply 5V to the circuit.

Check out the rest of the tutorials here.

ATX Lab Power Supply – Planning Progress 1

I think that this project is going to take me some time … there are some bits of information that I need to gather before I can really do very much, some case modifications and some decisions about how I go about providing connections to the power outputs.

image

I have been given an Antec SmartPower 2.0 500W power supply with dual “pull through” cooling fans. The power supply seems to have all that I need (and some redundant bits that I need to plan how to handle).

I downloaded the manual from the Antec website and it seems to have most of the information that I need … so far.

My requirements are:

  • Break out connections for 3.3v, 5v and 12v;
  • Switch between 12V and variable power output;
  • voltmeter display to show voltage output on 12V/variable;
  • 5V USB output;
  • LED power indicator;
  • LED standby indicator.

To achieve the 12V/Variable I plan to put in a SPDT toggle switch to select either 12V or Variable. When the 12V/Variable is in either state, for the voltage to be displayed on a voltmeter. This means that I’m going to have to dedicate one of the 5V outputs to power the voltmeter.

The 5V USB should be fairly straight forward, I just need to connect the outer two pins on the USB connection block  to 5V and GND (the right way around).

I could embed the power supply inside a purpose built case that simply connects the power supply 20+4 connector into a compatible PCB connector and then break the connections out from that. That would also mean that, should I need to change the power supply later, that it is independent of the case and breakouts.

Anyway, I’m going to do some research and mull over the options before I do anything else with this project.

Paypal Donations

Donations to help me to keep up the lunacy are greatly appreciated, but NOT mandatory.