Show Posts
Pages: 1 [2] 3 4 ... 6
16  Using Arduino / Project Guidance / Re: Buy List for a SMS serveur ? on: February 01, 2014, 04:55:40 am
I'm not sure the shield has a voltage regulator on it, and the yun only work on 5V so I think you should rather use a 5V power supply than a 12V one...
17  Using Arduino / Programming Questions / Re: Led cube and IR remote code not working together on: October 22, 2013, 12:20:11 pm
Never mind, It was actually a problem in my hardware desing...
18  Using Arduino / Programming Questions / Led cube and IR remote code not working together on: October 22, 2013, 10:49:42 am
Hi, I've been working on my first 5x5x5 LED cube, And everything worked out well.
The thing if I tried to add support for a remote so I could control the brightness and and change animation.
The cube works fine until I use the remote... Then it freezes.
The ir remote uses timer 2, and the updating process of my cube uses timer one, so I don't think the problem would come from there.
Here's my code:
Code:
*  This code mostly comes from Kevin Darrah's code for it's 8x8x8 rgb led cube
 www.kevindarrah.com
 */
#include <SchedulerARMAVR.h>//for handeling the execution of the animations and recieving
#include <IRremote.h>//These two includes are for the IR remote
#include <IRremoteInt.h>
#include <SPI.h>//SPI for the shift registers
#define latch_pin 2
#define RECV_PIN 10
//byte ledMap[5][25];
byte num_anim=5;// number of animations I wrote for the moment
byte BAMcounter=0;// These two counters are needed for the bit angle modulation
byte BAMbit=0;//
byte data[5][4][4];// These  bytes hold the data send to the shift registers
//the first "dimention" represent the levels, the second one contains the bits matching each
//connection out of the shift registers and the third "dimention" is fort each bit of the bit
//angle modulation
byte level=0;//the level at which we are
byte pwm_max=15;// max luminosity, useful when controling the overall brightness of the cube
char animation=-1;//current animation
char lastanim=0;// animation we where at when the cube is put in sleep mode
//IRrecv reciver(RECV_PIN);// reciver object for the IR remote
//decode_results IRcomand;//object to hold the data from the remote
unsigned long last_comand=0;// in case of continuous press on the remote
void setup() {
  // put your setup code here, to run once:
  randomSeed(39);// intizlize random
  SPI.setBitOrder(MSBFIRST);//config for the spi
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  pinMode(13,OUTPUT);//for spi
  pinMode(11,OUTPUT);//for spi
  pinMode(latch_pin, OUTPUT);//needed to update the led cube
  for(int a=0;a<5;a++)//initialize the data so everything is turned of
    for(int b=0;b<4;b++)
      for(int c=0;c<4;c++)
      {
        data[a][b][c]=0;
      }
  for(int i=0;i<4;i++)//bit masks for the levels
    data[0][3][i]=B00000010;
  for(int i=0;i<4;i++)
    data[1][3][i]=B00000100;
  for(int i=0;i<4;i++)
    data[2][3][i]=B00001000;
  for(int i=0;i<4;i++)
    data[3][3][i]=B00010000;
  for(int i=0;i<4;i++)
    data[4][3][i]=B00100000;//until here

  noInterrupts();//seting up the timer 1, don't want to be interrupted
  TCCR1A=B00000000;//no pwm
  TCCR1B=B00001011;//clock div=64, couter mode
  TIMSK1=B00000010;//interupt on compare A
  OCR1A=25;//play with the valu so the update frequency is high enough
  //so there is no glitching, but not too high so we still have some cpu time
  SPI.begin();//init spi
  SPI.transfer(0);// clears shift register from all garbage from bootloader
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0);
  digitalWrite(2,HIGH);//clear outputs
  digitalWrite(2,LOW);//
  interrupts();// let the show begin
  //reciver.enableIRIn();// starts reciving IR from th remote uses timer 2
  Scheduler.startLoop(humanHandeler);// starts the loop for human interaction
  // Serial.begin(115200);//for debugging
}

void loop() {
  // put your main code here, to run repeatedly:
  animation++;//go to the next animation
  switch(animation)
  {
  case -2://led cube is sleeping
    for(byte a=0;a<5;a++)//blanks out everything
      for(byte b=0;b<5;b++)
        for(byte c=0;c<5;c++)
          LED(a,b,c,0);
    animation--;
    //keeps the counter from incrementing
    break;
  case 0:
    walls();
    break;
  case 1:
    cross();
  case 2:
    heartGlow();
    break;
  case 3:
    travel();
    break;
  case 4:
    rain();
    break;
  case 5:
    fill();
    break;
  default:
    animation=-1;//if we are over 5, then go back to begining
    break;
  }

  yield();//scheduler control
}

void humanHandeler()//handeling  remote orders
{
  if(reciver.decode(&IRcomand))//did we recived anything?
    if(IRcomand.decode_type==1)//did it came from the good remote?
    {
      switch(IRcomand.value)
      {
      case 0x40BF906F://power
        if(animation!=-2)//not in sleep so let's sleep
        {
          lastanim=animation;//save current animation
          animation=-2;//set -2 so it goes to sleep
        }
        else
          animation=lastanim;//recover from sleep, where we left
        break;
      case 0x40BFB04F://plus
        pwm_max=constrain(pwm_max++,0,15);//increment pwm_max, but not exeding 15
        break;
      case 0x40BF708F://minus
        pwm_max=constrain(pwm_max--,0,15);//decrement pwm max but not under 0
        break;
      case 0x40BF50AF://left
        animation--;//go one animation back
        if(animation<-1) animation=num_anim-1;//roll over
        break;
      case 0x40BFA857://right
        animation++;//one animation forward
        if(animation>num_anim-1)//roll over
          animation=-1;
        break;
        /*case 0xFFFFFFFF://repeat
         switch(last_comand)//starts over with previous ir code
         {
         case 0x40BF906F:
         if(animation!=-2)
         {
         lastanim=animation;
         animation=-2;
         }
         else
         animation=lastanim;
         break;
         case 0x40BFB04F:
         pwm_max=constrain(pwm_max++,0,15);
         break;
         case 0x40BF708F:
         pwm_max=constrain(pwm_max--,0,15);
         break;
         case 0x40BF50AF:
         animation--;
         if(animation<-1) animation=num_anim-1;
         break;
         case 0x40BFA857:
         animation++;
         if(animation>num_anim-1)
         animation=-1;
         break;
         }
         break;
      default:
        break;
      }
      if(IRcomand.value!=0xFFFFFFFF)//save ir code if not a repeat code
        last_comand=IRcomand.value;
    }

  reciver.resume();// start reciving ir codes again
  yield();//scheduling control
}

void LED(byte x, byte y, byte z, byte pwm)// this function translates the coordiantes of
//the led and its brightness into the data bytes
{
  if(pwm&B00000001)//checks for first bit of pwm
  {
    bitSet(data[z][(5*y+x)/8][0],(5*y+x)%8);//level if first dimention (z)
    //(5*y+x)/8 returns the byte and (5*y+x)%8 returns the bit
  }
  else{
    bitClear(data[z][(5*y+x)/8][0],(5*y+x)%8);
  }
  if(pwm&B00000010)//check second bit
  {
    bitSet(data[z][(5*y+x)/8][1],(5*y+x)%8);
  }
  else{
    bitClear(data[z][(5*y+x)/8][1],(5*y+x)%8);
  }
  if(pwm&B00000100)//check third bit
  {
    bitSet(data[z][(5*y+x)/8][2],(5*y+x)%8);
  }
  else{
    bitClear(data[z][(5*y+x)/8][2],(5*y+x)%8);
  }
  if(pwm&B00001000)//check fourth bit
  {
    bitSet(data[z][(5*y+x)/8][3],(5*y+x)%8);
  }
  else{
    bitClear(data[z][(5*y+x)/8][3],(5*y+x)%8);
  }
}

ISR(TIMER1_COMPA_vect){//isr, updating the led cube
//here the BAM_counter keeps track of where we are updationg the cube
  if(BAMcounter==4)//when reaching 4, bit one is done
    BAMbit++;//go to next bit
  else
    if(BAMcounter==12)//when reaching 12, bit 2 is done
      BAMbit++;//go to next bit
    else
      if(BAMcounter==28)//when reaching 28, bit 3 is done
        BAMbit++;//go to next bit

  BAMcounter++;//each interrupt increment this couter
  for(byte i=0;i<4;i++)//transfer data bytes to shift register
    SPI.transfer(data[level][3-i][BAMbit]);
  bitSet(PORTD,2);//port manipulation for latching so everything is faster
  bitClear(PORTD,2);
  level++;//level goes up
  if(level==5)//reset level
    level=0;
  if(BAMcounter==72)//rester BAM_counter and BAM_bit
  {
    BAMcounter=0;
    BAMbit=0;
  }

}
I didn't inculde the animations because they are only a bunch of 'for' loops, of 'LED()' calls and of 'Scheduler.delay()'
If somebody find out what could be the problem I would be very grateful smiley-grin
19  Using Arduino / Project Guidance / Re: CapSensing questions on: October 22, 2013, 03:52:52 am
Hi, 
If you read carefully the playground page of the capSense library, you can read that

1) these reading you get are not supposed to be constant. They do represent the capacitance of the capacitors virtualy connected to ground (look at the picture on the library page: http://playground.arduino.cc//Main/CapacitiveSensor?from=Main.CapSense) But it does not have any unit.

To answer the other questions you need to understand how it measures the capacitance.
What the library is actually returning if the time that the capacitor made by you and the aluminium foil takes to go to the same state (high or low) of the send pin, when it changes (ie. goes from low to high, or from high to low)
This time is representative of the capacitance because the time required to load a capacitor depends on it's capacitance, but it is not a very accurate way of doing it.
It might not be very clear(english is not my native language) but If you look at the playground page and at the code you will find answers to all your questions.
Hope I helped...
20  Using Arduino / General Electronics / Re: A good shop for electronics on: October 07, 2013, 02:12:02 pm
I didn't saw that... Thanks smiley
21  Using Arduino / General Electronics / A good shop for electronics on: October 07, 2013, 01:21:35 pm
Hi, I don't know if this topic really belongs in this category but anyway, I want to start pretty big projects, so I am looking for a good electronic component suplier. Could you suggest one, as I don't know which one is the better.
Thanks
22  Using Arduino / Installation & Troubleshooting / Error :bootloader.tool param missing on: September 22, 2013, 11:49:35 am
Hi, I am trying to follow this tutorial: http://arduino.cc/en/Tutorial/ArduinoToBreadboard (the last part, without the crystal), but when I try to burn the bootloader this error shows up: error bootloader.tool parameter missing
I checked i the provided "boards.txt" file and there isn't this entry.
Does anyone know what to add to the file so it works?
23  Products / Arduino Due / Re: Frustrated on: September 03, 2013, 01:57:50 pm
Did you try to look at the Sam3X8E 's datasheet?
[url]http://www.atmel.com/devices/SAM3X8E.aspx?tab=documents[\url][url]
(The second docment)
24  Products / Arduino Due / Re: Serial.read problems with Arduino Due on: August 28, 2013, 11:36:44 am
Add code tags to your code. Try this:
Code:
...
byte LVcmd [11];
...
for(int i=0;i<11;i++)
{
LVcmd[i]=Serial.read();
}
...
25  Products / Arduino Due / Re: ADMUX in Arduino Due on: August 27, 2013, 12:49:55 am
This code relies on the internal reference present on the AVR chips, which doesn't exist on the SAM3X8E, so I don't think you may get the code to work.
26  Products / Arduino Due / Re: arduino due + li-ion battery + usb charging on: June 28, 2013, 01:28:54 am
When fully charged, li-ion batteries have a voltage close to 4.2V, so I would recommend to connect it to the 3.3V of the due. Also keep in mind that the due does not have a charging circuit, so be careful when connecting the battery and the usb at the same time (it might explode)

The fio is different because it has an integrated charging circuit, to protect the battery and the board.
27  Products / Arduino Due / Re: How many inputs can the Due handle? on: May 04, 2013, 03:47:12 am
All of them smiley
Reference of interrupts:
Quote
The Arduino Due board has powerful interrupt capabilities that allows you to attach an interrupt function on all available pins. You can directly specify the pin number in attachInterrupt().
28  Products / Arduino Due / Re: SPI across two Arduino DUE's on: March 30, 2013, 04:16:50 am
Hi, the SPI library only supports master mode:
Quote
[...]Since this library supports only master mode[...]
(quote from the library page)
So the Slave due is acting as a master too. Unfortunately I don't know how the spi is implemented in the due, so I can't help more.
29  Products / Arduino Due / Re: for calculation of of simple multiplication on: March 15, 2013, 12:01:35 pm
Try
Code:
Serial.print(a,n)
with n being the number of decimals that must be displayed.
30  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Motor Shield R3 Help on: February 28, 2013, 12:44:49 pm
Hello,

one shield with one stepper is nice for one direction.
Is it possible to connect a second Motor Shield R3 at the Arduino?

Thanks for information
yes you can use two, but not one on the other, you must put the other one next to your Arduino connect the pins of the "side-car" shield to others pins than the ones used by the first one ex:

==============================================
Arduino pin| shield on the Arduino | side-car shield
=========|===================|================
0              |NC                          |NC
1              |NC                          |NC
2              |NC                          |BRAKE A
3              | PWM A                    |NC
4              |NC                          |BRAKE B
5              |NC                          |PWM A
6              |NC                          |PWM B
7              |NC                          |DIR A
8              |BRAKE B                   |NC
9              |BRAKE A                  |NC
10            |NC                          |DIR B
11            |PWM B                     |NC
12            |DIR A                       |NC
13            |DIR B                       |NC
A1            |SNS 0                      |NC
A2            |SNS 1                      |NC
A3            |NC                         |SNS 0
A4            |NC                         |SNS 1
A5            |NC                         |NC
======================================
(you can change the pins connection of the side car shield if you want but make sure that you don't use a used pin by the "on Arduino" shield.
Of course you also need to connect the Vin pin, Gnd pin and 5V pin.

I don't have two shield so I can't show you a photo but it is something easy to do.
Pages: 1 [2] 3 4 ... 6