Colors Shield 1.1 / Colorduino keine Ausgabe

Hallo,

ich habe das Colors Shield 1.1 von iteadstudio.com und versuche gerade mit dem ColorduinoPlasma Sample eine Ausgabe zu erzielen. Leider erfolglos.
Nach der Programmierung leuchtet die 3 Reihe vertical 2x in lila auf und danach ist ruhe.

Ich habe das 8x8 Matrix Shield abgenommen und mal VCC zu den Blue/Red/Green Kontakten gemessen. Überall nur ~0.05V
Ist das Color Shield defekt oder muss ich es noch irgendwie speziell Flashen/Programmieren?

Zur Info: Ich habe die Librarie von #include WProgram.h zu #include Arduino.h. geändert, da ich sonst nicht kompilieren konnte.

Den demokode auf http://iteadstudio.com/store/index.php?main_page=product_info&cPath=18&products_id=312 bzw das Baiscpiel das mit der Library mitgeliefert wurde hast Du versucht?
Hast Du das Ledmatrixmodul verkehrtherum auf den Colorduino gesteckt?

Grüße Uwe

Hallo Uwe,

ja Beispiel Code habe ich versucht. Ebenso das LED Matrix "shield" gemessen. Die LED funktionieren und die Richtung stimmt auch, jedoch gibt es kein Signal von dem Colors Shield. :confused:
Habe das Shield bei Komputer.de gekauft. Der Herr war sehr freundlich und hat mir gleich angeboten ein neues Exemplar zu schicken. Das alte soll ich per Post zurück senden. Super Service. Bin mal gespannt ob es mit dem neuen vernünftig läuft, oder ob ich einen Fehler gemacht habe..

Ich bin verwirrt. Habs gerade am Arduino UNO getestet und da läuft es problemlos???
Mein Arduino MEGA verweigert seine Dienste. Woran kann sowas liegen?

Der Arduino 2009/UNO ist nicht 100% kompatibel mit dem Arduino Mega/Mega2560 (bezogen auf die pins des Arduino 2009/UNO. Der Hauptunterschied ist die Position der I2C schnittstelle. Beim Uno ist sie auf den PINs A4 und A5 während beim Mega auf den PINs 20 und 21

Dieses Board laut schaldbild benutzt die digitalen Ausgänge D3 , D4 und bis D8 bis D13 für die Ansteuerung des Anodentreibes M54564 und D6, D7, A0,A1 und A2 für die Ansteuerung des Kathodentreibers DM163.
Das Board mußte eigentlich auch auf dem Arduino Mega funktionieren auch wenn die Beschreibung nur den Arduino 2009 / UNO nennt.

Welche version des Mega bzw UNO hast Du?
Grüße Uwe

Hi Uwe, danke für deine schnelle Hilfe.
Hab ein MEGA 2560 R3 und ein Arduino Ethernet. Dachte bislang, dass die Boards alle gleich sind und neben der Geschwindigkeit, nur die PIN IN/OUT den Unterschied liefern.

Die R3 Versonen haben 2x2 neue Pins (gegenüber den Vorgängerversionen) die Pins nach Uref-D13 sind die I2C Schnittstelle um die Shields am UNO r3 und MEGA2560 R3 betreiben zu können.

Das Problem kann nicht die HW sein sondern der Sketch. Da dei beiden Arduinos verschiedene ATmegas verwenden, die verschiedene Register haben könnte das Problem da liegen.

Grüße Uwe

Ne Idee wen ich da mal anfragen könnte? Ich hab mir die Sketches und Libraries angeschaut aber nichts besonderes dazu gefunden..

da2001:
Ne Idee wen ich da mal anfragen könnte? Ich hab mir die Sketches und Libraries angeschaut aber nichts besonderes dazu gefunden..

UNS!!!

Zum testen habe ich die Colorduino Lib 1.2 genommen und das Plasmasample. Leider bleibt das Matrix shield dunkel..

Sketch:

	/*
  ColorduinoPlasma - Plasma demo using Colorduino Library for Arduino
  Copyright (c) 2011 Sam C. Lin lincomatic@hotmail.com ALL RIGHTS RESERVED

  based on  Color cycling plasma   
    Version 0.1 - 8 July 2009
    Copyright (c) 2009 Ben Combee.  All right reserved.
    Copyright (c) 2009 Ken Corey.  All right reserved.
    Copyright (c) 2008 Windell H. Oskay.  All right reserved.
    Copyright (c) 2011 Sam C. Lin All Rights Reserved

  This demo is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This demo is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <Colorduino.h>

typedef struct
{
  unsigned char r;
  unsigned char g;
  unsigned char b;
} ColorRGB;

//a color with 3 components: h, s and v
typedef struct 
{
  unsigned char h;
  unsigned char s;
  unsigned char v;
} ColorHSV;

unsigned char plasma[ColorduinoScreenWidth][ColorduinoScreenHeight];
long paletteShift;


//Converts an HSV color to RGB color
void HSVtoRGB(void *vRGB, void *vHSV) 
{
  float r, g, b, h, s, v; //this function works with floats between 0 and 1
  float f, p, q, t;
  int i;
  ColorRGB *colorRGB=(ColorRGB *)vRGB;
  ColorHSV *colorHSV=(ColorHSV *)vHSV;

  h = (float)(colorHSV->h / 256.0);
  s = (float)(colorHSV->s / 256.0);
  v = (float)(colorHSV->v / 256.0);

  //if saturation is 0, the color is a shade of grey
  if(s == 0.0) {
    b = v;
    g = b;
    r = g;
  }
  //if saturation > 0, more complex calculations are needed
  else
  {
    h *= 6.0; //to bring hue to a number between 0 and 6, better for the calculations
    i = (int)(floor(h)); //e.g. 2.7 becomes 2 and 3.01 becomes 3 or 4.9999 becomes 4
    f = h - i;//the fractional part of h

    p = (float)(v * (1.0 - s));
    q = (float)(v * (1.0 - (s * f)));
    t = (float)(v * (1.0 - (s * (1.0 - f))));

    switch(i)
    {
      case 0: r=v; g=t; b=p; break;
      case 1: r=q; g=v; b=p; break;
      case 2: r=p; g=v; b=t; break;
      case 3: r=p; g=q; b=v; break;
      case 4: r=t; g=p; b=v; break;
      case 5: r=v; g=p; b=q; break;
      default: r = g = b = 0; break;
    }
  }
  colorRGB->r = (int)(r * 255.0);
  colorRGB->g = (int)(g * 255.0);
  colorRGB->b = (int)(b * 255.0);
}

float
dist(float a, float b, float c, float d) 
{
  return sqrt((c-a)*(c-a)+(d-b)*(d-b));
}


void
plasma_morph()
{
  unsigned char x,y;
  float value;
  ColorRGB colorRGB;
  ColorHSV colorHSV;

  for(y = 0; y < ColorduinoScreenHeight; y++)
    for(x = 0; x < ColorduinoScreenWidth; x++) {
      {
	value = sin(dist(x + paletteShift, y, 128.0, 128.0) / 8.0)
	  + sin(dist(x, y, 64.0, 64.0) / 8.0)
	  + sin(dist(x, y + paletteShift / 7, 192.0, 64) / 7.0)
	  + sin(dist(x, y, 192.0, 100.0) / 8.0);
	colorHSV.h=(unsigned char)((value) * 128)&0xff;
	colorHSV.s=255; 
	colorHSV.v=255;
	HSVtoRGB(&colorRGB, &colorHSV);
	
	Colorduino.SetPixel(x, y, colorRGB.r, colorRGB.g, colorRGB.b);
      }
  }
  paletteShift++;

  Colorduino.FlipPage(); // swap screen buffers to show it
}

/********************************************************
Name: ColorFill
Function: Fill the frame with a color
Parameter:R: the value of RED.   Range:RED 0~255
          G: the value of GREEN. Range:RED 0~255
          B: the value of BLUE.  Range:RED 0~255
********************************************************/
void ColorFill(unsigned char R,unsigned char G,unsigned char B)
{
  PixelRGB *p = Colorduino.GetPixel(0,0);
  for (unsigned char y=0;y<ColorduinoScreenWidth;y++) {
    for(unsigned char x=0;x<ColorduinoScreenHeight;x++) {
      p->r = R;
      p->g = G;
      p->b = B;
      p++;
    }
  }
  
  Colorduino.FlipPage();
}

void setup()
{
  Colorduino.Init(); // initialize the board
  
  // compensate for relative intensity differences in R/G/B brightness
  // array of 6-bit base values for RGB (0~63)
  // whiteBalVal[0]=red
  // whiteBalVal[1]=green
  // whiteBalVal[2]=blue
  unsigned char whiteBalVal[3] = {36,63,63}; // for LEDSEE 6x6cm round matrix
  Colorduino.SetWhiteBal(whiteBalVal);
  
  
  // start with morphing plasma, but allow going to color cycling if desired.
  paletteShift=128000;
  unsigned char bcolor;

  //generate the plasma once
  for(unsigned char y = 0; y < ColorduinoScreenHeight; y++)
    for(unsigned char x = 0; x < ColorduinoScreenWidth; x++)
    {
      //the plasma buffer is a sum of sines
      bcolor = (unsigned char)
      (
            128.0 + (128.0 * sin(x*8.0 / 16.0))
          + 128.0 + (128.0 * sin(y*8.0 / 16.0))
      ) / 2;
      plasma[x][y] = bcolor;
    }
    
 // to adjust white balance you can uncomment this line
 // and comment out the plasma_morph() in loop()
 // and then experiment with whiteBalVal above
 // ColorFill(255,255,255);
}

void loop()
{
  plasma_morph();
}

Colordruino.cpp

/*
  Colorduino - Colorduino Library for Arduino V1.1
  Copyright (c) 2011 Sam C. Lin lincomatic@hotmail.com ALL RIGHTS RESERVED
  based on C code by zzy@iteadstudio
    Copyright (c) 2010 zzy@IteadStudio.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
#include "Colorduino.h"

void ColorduinoObject::LED_Delay(unsigned char i)
{
  unsigned int y;
  y = i * 10;
  while(y--);
}

// compensate for relative intensity differences in R/G/B brightness
// array of 6-bit base values for RGB (0~63)
// wbval[0]=red
// wbval[1]=green
// wbval[2]=blue
void ColorduinoObject::SetWhiteBal(unsigned char wbval[3])
{
  LED_LAT_CLR;
  LED_SLB_CLR;
  for(unsigned char k=0;k<ColorduinoScreenHeight;k++)
    for(unsigned char i = 3;i > 0 ;i--)
    {
      unsigned char temp = wbval[i-1]<<2;
      for(unsigned char j = 0;j<6;j++)
      {
        if(temp &0x80)
          LED_SDA_SET;
        else
          LED_SDA_CLR;
        
        temp =temp << 1;
        LED_SCL_CLR;
        LED_SCL_SET;
    }
  }
  LED_SLB_SET;
}


// global instance
ColorduinoObject Colorduino;


ISR(TIMER2_OVF_vect)          //Timer2  Service 
{ 
  // 
 // ISR fires every 256-TCNT2 ticks
 // so if TCNT2 = 100, ISR fires every 156 ticks
 // prescaler = 128 so ISR fires every 16MHz / 128 = 125KHz
 // 125KHz / 156 = 801.282Hz / 8 rows = 100.16Hz refresh rate
 // if TCNT2 = 61, ISR fires every 256 - 61 = 195 ticks
 // 125KHz / 195 = 641.026Hz / 8 rows = 80.128Hz refresh rate
  //  TCNT2 = 100;
  TCNT2 = 61;
  close_all_lines;  
  Colorduino.run();
  Colorduino.open_line(Colorduino.line);
  if (++Colorduino.line > 7) Colorduino.line = 0;
}
/****************************************************
the LED Hardware operate functions zone
****************************************************/

/***************************************************
the LED datas operate functions zone
***************************************************/

void ColorduinoObject::run()
{
  LED_SLB_SET;
  LED_LAT_CLR;
  PixelRGB *pixel = GetDrawPixel(0,line);
  for(unsigned char x=0;x<ColorduinoScreenWidth;x++)
  {
    unsigned char temp = pixel->b;
    unsigned char p;
    for(p=0;p<ColorduinoBitsPerColor;p++) {
      if(temp & 0x80)
	LED_SDA_SET;
      else
	LED_SDA_CLR;
      temp <<= 1;  
      LED_SCL_CLR;
      LED_SCL_SET;
    }
    temp = pixel->g;
    for(p=0;p<ColorduinoBitsPerColor;p++) {
      if(temp & 0x80)
	LED_SDA_SET;
      else
	LED_SDA_CLR;
      temp <<= 1;  
      LED_SCL_CLR;
      LED_SCL_SET;
    }
    temp = pixel->r;
    for(p=0;p<ColorduinoBitsPerColor;p++) {
      if(temp & 0x80)
	LED_SDA_SET;
      else
	LED_SDA_CLR;
      temp <<= 1;  
      LED_SCL_CLR;
      LED_SCL_SET;
    }
    pixel++;
  }
  LED_LAT_SET;
  LED_LAT_CLR;
}

Colorduino.h

/*
  Colorduino - Colorduino Library for Arduino V1.1
  Copyright (c) 2011 Sam C. Lin lincomatic@hotmail.com ALL RIGHTS RESERVED
  based on C code by zzy@iteadstudio
    Copyright (c) 2010 zzy@IteadStudio.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
#ifndef _COLORDUINO_H_
#define _COLORDUINO_H_
#include "Arduino.h"
#include <avr/pgmspace.h> 
#include <avr/io.h>
#include <avr/interrupt.h>

#define ColorduinoBitsPerColor 8

#define ColorduinoScreenWidth 8
#define ColorduinoScreenHeight 8

/*****************************
define the IO
*****************************/
#define RST_BIT 0x04
#define LAT_BIT 0x02
#define SLB_BIT 0x01
#define SCL_BIT 0x40
#define SDA_BIT 0x80

#define RST PORTC
#define LAT PORTC
#define SLB PORTC
#define SDA PORTD
#define SCL PORTD

#define open_line0	{PORTB=0x01;}
#define open_line1	{PORTB=0x02;}
#define open_line2	{PORTB=0x04;}
#define open_line3	{PORTB=0x08;}
#define open_line4	{PORTB=0x10;}
#define open_line5	{PORTB=0x20;}
#define open_line6	{PORTD=0x08;}
#define open_line7	{PORTD=0x10;}
#define close_all_lines	{PORTD=0x00;PORTB=0x00;}

#define LED_RST_SET RST|=RST_BIT
#define LED_RST_CLR RST&=~RST_BIT
#define LED_SDA_SET SDA|=SDA_BIT
#define LED_SDA_CLR SDA&=~SDA_BIT
#define LED_SCL_SET SCL|=SCL_BIT
#define LED_SCL_CLR SCL&=~SCL_BIT
#define LED_LAT_SET LAT|=LAT_BIT
#define LED_LAT_CLR LAT&=~LAT_BIT
#define LED_SLB_SET SLB|=SLB_BIT
#define LED_SLB_CLR SLB&=~SLB_BIT

typedef struct pixelRGB {
  unsigned char r;
  unsigned char g;
  unsigned char b;
} PixelRGB;

class ColorduinoObject {
public:
  PixelRGB frameBuffer0[ColorduinoScreenWidth*ColorduinoScreenHeight];
  PixelRGB frameBuffer1[ColorduinoScreenWidth*ColorduinoScreenHeight];
  PixelRGB *curDrawFrame;
  PixelRGB *curWriteFrame;
  unsigned char line;

  ColorduinoObject() {
    line = 0;
    curWriteFrame = frameBuffer0;
    curDrawFrame = frameBuffer1;
  }

  void _IO_Init()
  {
    DDRD = 0xff; // set all pins direction of PortD
    DDRC = 0xff; // set all pins direction of PortC
    DDRB = 0xff; // set all pins direction of PortB
    
    PORTD = 0x00; // set all pins output is low of PortD
    PORTC = 0x00; // set all pins output is low of PortC
    PORTB = 0x00; // set all pins output is low of PortB
  }
  
  void LED_Delay(unsigned char i);
  
  void SetWhiteBal(unsigned char wbval[3]);

  void _LED_Init()
  {
    LED_RST_SET;
    LED_Delay(1);
    LED_RST_CLR;
    LED_Delay(1);
    LED_RST_SET;
    LED_Delay(1);
    
    line = 0;
  }

  void _TC2_Init()
  {
  // Arduino runs at 16 Mhz...
  // Timer Settings, for the Timer Control Register etc. , thank you internets. ATmega168 !
  // Timer2 (8bit) Settings:
  // prescaler (frequency divider) values:   CS22    CS21   CS20
  //                                           0       0      0    stopped
  //                                           0       0      1      /1 
  //                                           0       1      0      /8 
  //                                           0       1      1      /32
  //                                           1       0      0      /64 
  //                                           1       0      1      /128
  //                                           1       1      0      /256
  //                                           1       1      1      /1024
  // TCNT2 increments every  = 16MHz / prescaler

    // set prescaler to 128 -> TCNT2 freq = 125KHz
    TCCR2B |= ((1<<CS22)|(1<<CS20));
    TCCR2B &= ~((1<<CS21));   

    TCCR2A &= ~((1<<WGM21) | (1<<WGM20));   // Use normal mode
    ASSR |= (1<<AS2);       // Use internal clock - external clock not used in Arduino
    TIMSK2 |= (1<<TOIE2) | (0<<OCIE2B);   //Timer2 Overflow Interrupt Enable
    TCNT2 = 0xff;
    sei();
  }
  
  void open_line(unsigned char x)
  {
    switch (x)
      {  
      case 0 :open_line0;
	break;
      case 1 :open_line1;
	break;
      case 2 :open_line2;
	break;
      case 3 :open_line3;
	break;
      case 4 :open_line4;
	break;
      case 5 :open_line5;
	break;
      case 6 :open_line6;
	break;
      case 7 :open_line7;
	break;
      default: close_all_lines;
	break;
      }
  }

  void Init() {
    _IO_Init();           //Init IO
    _LED_Init();          //Init LED Hardware
    _TC2_Init();          //Init Timer/Count2
  }

  void FlipPage() {
    cli();
    // swap frame buffers
    PixelRGB *tmp = curDrawFrame;
    curDrawFrame = curWriteFrame;
    curWriteFrame = tmp;
    sei();
  }

  // get a pixel for writing in the offscreen framebuffer
  PixelRGB *GetPixel(unsigned char x,unsigned char y) {
    return curWriteFrame + (y * ColorduinoScreenWidth) + x;
  }

  // get a pixel from the active framebuffer
  PixelRGB *GetDrawPixel(unsigned char x,unsigned char y) {
    return curDrawFrame + (y * ColorduinoScreenWidth) + x;
  }

  // set a pixel in the offscreen frame buffer
  void SetPixel(unsigned char x, unsigned char y, unsigned char r, unsigned char g, unsigned char b)
  {
    PixelRGB *p = GetPixel(x,y);
    p->r = r;
    p->g = g;
    p->b = b;
  }

  void run();
};

extern ColorduinoObject Colorduino;

#endif // _COLORDUINO_H_