Showing posts with label attiny85. Show all posts
Showing posts with label attiny85. Show all posts

Friday, February 28, 2020

ATTiny Charlieplex 4 RGB leds

Experimented using 4 charlieplexed RGB leds on a attiny85.
This experiment was done some time ago, and due to the result (watch video below) i hesitated to post it as at that time it was not complete successful.  There are several excellent resource that explain charlieplexing. Therefor i will not try to explain it in detail. In short as leds only light up when the current flows in one direction you can control more leds to a circuit.
I used the code below.

CODE

void setup() {              
  // charlieplex 4 RGB leds 0 1 2 3
  // initialize the digital pin as an output.
}

// the loop routine runs over and over again forever:
void loop() {
 int mydelay = 1000;

  LEDon(3, 2);  // 1R
  delay(mydelay);
  LEDon(3, 0);  // 1G
  delay(mydelay);
  LEDon(3, 1);  // 1B
  delay(mydelay);

  LEDon(0, 1);  // 2R
  delay( mydelay );
  LEDon(0, 3);  // 2G
  delay( mydelay );
  LEDon(0, 2);  // 2B
  delay( mydelay );

  LEDon(1, 0);  // 3R
  delay(mydelay);
  LEDon(1, 2);  // 3G
  delay(mydelay);
  LEDon(1, 3);  // 3B
  delay(mydelay);

  LEDon(2, 3);  // 4R
  delay(mydelay);
  LEDon(2, 1);  // 4G
  delay(mydelay);
  LEDon(2, 0);  // 4B
  delay(mydelay);
}

void LEDon( int gnd, int vin) {
  pinMode(0, INPUT);
  pinMode(1, INPUT);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
//  pinMode(4, INPUT);
//  pinMode(5, INPUT);

  pinMode(vin, OUTPUT);
  pinMode(gnd, OUTPUT);
  digitalWrite(vin, HIGH);
  digitalWrite(gnd, LOW);
}

ENDCODE

When you watch the video you seen some unwanted / unexpected flashes of an RGB led.
This is due to the fact that the attiny85 has an on-board led connected to one of the pins. This interferes with the charlieplexing. To remove this unwanted behavior of the RGB led you need to remove this led.
My first idea was to first make a recording of the correct behaving RGB leds before posting everything on my blog. I did not yet made a video recording after modifying an attiny85. However i later made a custom PCB for charlieplexing. I now decided to post it withe the error due to the led and make later a posting about that PCB where you can see the correct functioning of the RGB leds.



Monday, December 23, 2019

ATTiny85 RGB led

An RGB Led with DuPont connectors from a previous post was tested with the attiny85 with Dupont female wires. the wire without resistor was connected to ground and the other led pins with the resistors to P0, P1 and P2.
As program i used the Example DigisparkRGB program. ( Examples \  DigisparkRGB \ DigisparkRGB  ).

#include <DigisparkRGB.h>
/*
 Digispark RGB

 This example shows how to use soft PWM to fade 3 colors.
 Note: This is only necessary for PB2 (pin 2) - Blue, as Red (pin 0) and Green (pin 1) as well as pin 4 support the standard Arduino analogWrite() function.

 This example code is in the public domain.
 */
byte RED = 0;
byte BLUE = 2;
byte GREEN = 1;
byte COLORS[] = {RED, BLUE, GREEN};

// the setup routine runs once when you press reset:
void setup()  {
  DigisparkRGBBegin();
}


void loop ()
{
//direction: up = true, down = false
boolean dir = true;
int i = 0;

while(1)
{
fade(COLORS[i%3], dir);
i++;
dir = !dir;
}
}
void fade(byte Led, boolean dir)
{
int i;

//if fading up
if (dir)
{
for (i = 0; i < 256; i++)
{
DigisparkRGB(Led, i);
DigisparkRGBDelay(25);//1);
}
}
else
{
for (i = 255; i >= 0; i--)
{
DigisparkRGB(Led, i);
DigisparkRGBDelay(25);//1);
}
}
}


A video of the result was posted on my YouTube channel :
(At that time this blogpost was not yet ready for publishing.)

As i was not very happy with the recorded colors, i tried to improve it by putting a white paper below the led. However the improvement was only minor and the real colors are different. I hope the video will at least give a little impression of the changing colors.
As all the colors are faded in the program i did not specially select the led color pins to be matched to the colors in the program (  RED = 0;  BLUE = 2;  GREEN = 1; )


Tuesday, August 20, 2019

ATTiny85 Mouse

The ATTiny85 can not only act as a keyboard, it can also act as a mouse.
Extreme caution if you use this as the program does not only mouse movements, it also clicks!
( Examples \ DigisparkMouse \ Mouse )

// DigiMouse test and usage documentation
// CAUTION!!!! This does click things!!!!!!!!
// Originally created by Sean Murphy (duckythescientist)

#include <DigiMouse.h>

void setup() {
  DigiMouse.begin(); //start or reenumerate USB - BREAKING CHANGE from old versions that didn't require this
}

void loop() {
  // If not using plentiful DigiMouse.delay(), make sure to call
  // DigiMouse.update() at least every 50ms

  // move across the screen
  // these are signed chars
  DigiMouse.moveY(10); //down 10
  DigiMouse.delay(500);
  DigiMouse.moveX(20); //right 20
  DigiMouse.delay(500);
  DigiMouse.scroll(5);
  DigiMouse.delay(500);

  // or DigiMouse.move(X, Y, scroll) works

  // three buttons are the three LSBs of an unsigned char
  DigiMouse.setButtons(1<<0); //left click
  DigiMouse.delay(500);
  DigiMouse.setButtons(0); //unclick all
  DigiMouse.delay(500);

  //or you can use these functions to click
  DigiMouse.rightClick();
  DigiMouse.delay(500);
  DigiMouse.leftClick();
  DigiMouse.delay(500);
  DigiMouse.middleClick();
  DigiMouse.delay(500);

  //for compatability with other libraries you can also use DigiMouse.move(X, Y, scroll, buttons)
}

I have tested this script on with my digispark and it worked. The movements are relative to the current position. I did not dare to experiment and move it to bottom left on a windows computer and use Microsoft start to start programs.

Monday, August 19, 2019

ATTiny85 Keyboard

One of the scripts that works on my attiny85 is a keyboard emulator.
All is done  with the next simple script that was available as a sample script in the library;
(   File \ Examples \ DigisparkKeyboard \  Keyboard )

#include "DigiKeyboard.h"

void setup() {
  // don't need to set anything up to use DigiKeyboard
}

void loop() {
  // this is generally not necessary but with some older systems it seems to
  // prevent missing the first character after a delay:
  DigiKeyboard.sendKeyStroke(0);

  // Type out this string letter by letter on the computer (assumes US-style
  // keyboard)
  DigiKeyboard.println("Hello Digispark!");

  // It's better to use DigiKeyboard.delay() over the regular Arduino delay()
  // if doing keyboard stuff because it keeps talking to the computer to make
  // sure the computer knows the keyboard is alive and connected
  DigiKeyboard.delay(5000);
}


After uploading the script the program starts so watch out where to put the cursor when uploading the script.
The Digispark USB reacts if it is a keyboard where the  "Hello Digispark!" is typed over and over again (with a delay  5000 ).

Hello Digispark!
Hello Digispark!
Hello Digispark!
Hello Digispark!

An application could be reading some sensor data on the attiny85 and outputting it e.g. in a spreadsheet.

Saturday, August 17, 2019

ATTiny85 USB module prepared for experiments

Recently received some ATTiny85 USB (Digispark Digistump) boards from Aliexpress.
I already experimented earlier with these small boards with chip that can be programmed easy by putting it in the USB connector of your computer.
These boards come (standard) with Dupont connectors (male or female) that you can solder on these small boards to conello Digispark!
nect it easy in experiments. I wanted a not connecting each time Dupont wires, a little bit more protection for the USB module more distance from my computer,.
To prepare a module i cut some wires with female Dupont connectors and soldered this directly to the module. (To prevent shortcuts i used female not the male).
With transparent heat shrink i added some protection for the board.

ATTiny PINs

On the side (bottom of the picture) are three connections (starting from USB)
5V(Color of my wire: )  Red
GND      (Color of my wire: ) Black
Vin(Color of my wire: ) Brown
Opposite to the USB connector are 6 holes
Digital-AnalogPWMI2CPSIColor
of my
 wire
P0(LED on
 model B)
ArefPWM0SDAMQSIWhite
P1(LED on
 model A)

PWM1
MISOViolet
P2
A1
SCLSCKBlue
P3USB+A3

xxGreen
P4USB-A2PWM4
xxYellow
P5(Reset on
some models)
A0

xxOrange

A simple blink script to test the module is
// the setup routine runs once when you press reset:
void setup() { // initialize the digital pin as an output. 

//  pinMode(0, OUTPUT); //LED on Model B
     pinMode(1, OUTPUT); //LED on Model A or Pro }

// the loop routine runs over and over again forever:
void loop() {
//  digitalWrite(0, HIGH);   // turn the LED on (HIGH is the voltage level)
     digitalWrite(1, HIGH);
     delay(500);               // wait for a second


//  digitalWrite(0, LOW);    // turn the LED off by making the voltage LOW
     digitalWrite(1, LOW);
     delay(500);               // wait for a second
}


The led on my module reacts on P1. So I expect i have a model A.