Show Posts
Pages: [1] 2 3 ... 6
1  Products / Arduino Due / Re: Nothing appears on arduino DUE screen on: March 12, 2014, 06:35:52 am
If you use the native port you muste use "SerialUSB" for communication with the computer.
2  Products / Arduino Due / Re: Arduino DUE PWM 60kHz Problem on: February 27, 2014, 05:12:38 am
If you are trying to control a servo or an ESC, maybe you should use the servo library provided with the arduino IDE:http://arduino.cc/en/Reference/Servo
3  Using Arduino / Programming Questions / Re: digitalRead question! on: February 26, 2014, 01:17:12 pm
Try something like this:
Code:
int couter=0;
boolean pressed=false;

if(digitalRead(pin)==HIGH&&pressed==false)
{
     counter++;
     pressed=true;
}
if(digitalRead(pin)==LOW&&pressed==true)
{
     pressed=false;
}
4  Using Arduino / General Electronics / Re: 5v wall wart as digital input on: February 17, 2014, 01:19:11 pm
@Zapro, Have you ever heard about switching power supplies? Almost every 5V Wall-wart now uses switching mode power suply, and the main "only" goes through an inductor and a diode. Still it is safe...
5  Using Arduino / Installation & Troubleshooting / Re: How to use external editor on: February 17, 2014, 08:17:43 am
Thanks for your answer smiley
6  Using Arduino / Installation & Troubleshooting / How to use external editor on: February 17, 2014, 05:54:56 am
Hi, I'd like to use an external editor with the arduino IDE, but when I click the "use external editor" in the settings window, all it does is disabling the coding area, I can't modify the content, nor paste code in it.
Can anyone guide me on how to actually use an external editor with the IDE?
7  Using Arduino / Programming Questions / Re: [SOLVED]Calculating temperature from thermistor on: February 15, 2014, 05:24:50 pm
It is a modified version of the original code that didn't worked.
The actual working code without the debugging output would be
Code:
#define cA1 0.003354016
#define cB1 0.000256985
#define cC1 0.000002620131
#define cD1 0.00000006383091
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(calctemp(analogRead(0)));
  delay(3000);
}

double calctemp(int value)
{
  return (pow((cA1+cB1*log(((10240000.0/(double)value)-10000)/10000.0)+cC1*pow(log(((10240000.0/(double)value)-10000)/10000.0),2.0)+cD1*pow(log(((10240000.0/(double)value)-10000)/10000.0),3.0)),-1.0)-273.15); 
}
8  Using Arduino / Programming Questions / Re: [SOLVED]Calculating temperature from thermistor on: February 15, 2014, 04:42:08 pm
I forgot to take that of, it was when I only got "nan" output ant though maybe there was an error in the data type...
anyway that print is always zero in the actual code since the calctemp() function does not return anything ...
9  Using Arduino / Programming Questions / Re: Calculating temperature from thermistor on: February 15, 2014, 04:04:29 pm
I re did the maths and found where the error was, now I get correct values for the temperature smiley

(code if anyone want to look at it)
Code:
#include <avr/math.h>
//double calctemp(int value);
#define cA1 0.003354016
#define cB1 0.000256985
#define cC1 0.000002620131
#define cD1 0.00000006383091
double temp;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  temp=calctemp(analogRead(0));
  Serial.println((double)temp);
  delay(3000);
}

double calctemp(int value)
{
  double temp;
  Serial.print("value: ");Serial.println(value);
  Serial.print("r/ r ref:");Serial.println(((10240000.0/(double)value)-10000.0)/10000.0);
  Serial.print("a1:");Serial.println(cA1,5);
  Serial.print("b1*log(...):");Serial.println(cB1*log((((10240000.0/(double)value)-10000.0)/10000.0)),5);
  Serial.print("c1*log^2(...):");Serial.println(cC1*pow(log(((10240000.0/(double)value)-10000)/10000.0),2),5);
  Serial.print("d1*log^3(...):");Serial.println(cD1*pow(log(((10240000.0/(double)value)-10000)/10000.0),3),5);
  Serial.print("sum:");Serial.println(cA1+cB1*log(((10240000.0/(double)value)-10000)/10000.0)+cC1*pow(log(((10240000.0/(double)value)-10000)/10000.0),2.0)+cD1*pow(log(((10240000.0/(double)value)-10000)/10000.0),3.0),5);
  Serial.print("final:");Serial.println(pow((cA1+cB1*log(((10240000.0/(double)value)-10000)/10000.0)+cC1*pow(log(((10240000.0/(double)value)-10000)/10000.0),2.0)+cD1*pow(log(((10240000.0/(double)value)-10000)/10000.0),3.0)),-1.0)-273.15);
  return temp;
 
}
10  Using Arduino / Programming Questions / Re: Calculating temperature from thermistor on: February 15, 2014, 01:26:43 pm
@mmcp42 I'll try that, thanks smiley
11  Using Arduino / Programming Questions / Re: Calculating temperature from thermistor on: February 15, 2014, 01:25:04 pm
it's like that:
12  Using Arduino / Programming Questions / [SOLVED]Calculating temperature from thermistor on: February 15, 2014, 12:14:45 pm
Hi, I want to get the temperature from a thermistor, so I made a simple a simple voltage divider (5V to thermistor,  10k between thermistor and ground, analogRead() between the 10k resistance and  the thermistor.
The nominal value of the thermistor is 10K too,
I looked the datasheet (http://www.vishay.com/docs/29049/ntcle100.pdf) and found a formula to get the temperature from the thermistor resistance:
Code:
K=3977
r ref=10k
A1=3.35401e-3
B1=2.56985e-4
C1=2.620131e-6
D1=6.383091e-8

T=(A1+B1*ln(r/r ref)+C1*ln^2(r/r ref)+D1*ln^3(R/r ref))^-1
and I found that using analogRead(), the resistance of the thermistor is
Code:
R=((1024-val)*10000)/val

Then I made a simple sketch to print the temperature on the serial monitor:
Code:
#include <avr/math.h>
//double calctemp(int value);
double temp;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  temp=calctemp(analogRead(0));
  Serial.println((double)temp);
  delay(1000);
}

double calctemp(int value)
{
  double temp;
 temp=(1.0/(0.00335401+0.000256985*(double)log((((double)((1024-value)*10000)/(double)value))/(double)10000)+0.000002620131*(double)pow(log((((double)((1024-value)*10000)/(double)value))/(double)10000),2.0)+0.00000006383091*(double)pow((double)log((((double)((1024-value)*10000)/(double)value))/(double)10000),3.0)));
  return temp;
  
}

But the problem is that I only get "nan" as output...
Has anyone a clue of what might be wrong?
13  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...
14  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...
15  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
Pages: [1] 2 3 ... 6