| Arduino Forum ::  Members :: Tom Carpenter
 Show Posts Pages: 1 ... 51 52 [53] 54 55 ... 106
 781 Using Arduino / Project Guidance / Re: LED Gurus? on: November 20, 2012, 05:51:51 pm Yup, Forward Current (aka If) = 140 [mA] = 0.14 [A]. Forward Voltage (aka Vf) is somewhere in the region of 1.4 [V] to 1.5 [V], so I would work on the theory that it is 1.45 [V] (the actual voltage will depend on the LED, temperature, current), but this approximate figure should be good enough.If we do the math, 5 diodes in series x 1.45 [V] each = 7.25 [V] dropped across the diodes. For a nominal 9 [V] supply, this leaves 9-7.25=1.75 [V] across your resistor. V=IR, so R = V/I = 1.75/0.14 = 12.5 [Ohm]. You will need an minimum P=IV = 0.14*1.75 = 0.245 [W] rated resistor.However... A 9V battery supplying 140mA will run flat very very very quickly. You would be lucky if you got half an hour out of it. The other thing is that you would be wasting a lot of energy in that resistor.
 782 Using Arduino / Microcontrollers / Re: SPI read write for 32bits data on: November 20, 2012, 04:27:18 pm Modified my example from before based on the datasheet:Code:#include union FourByte{    struct {      unsigned long value:24; //24bit register values go in here      byte command:8; //8bit command goes in here.    };    byte bit8[4]; //this is just used for efficient conversion of the above into 4 bytes.};void setup(){  SPI.begin();  SPI.setBitOrder(MSBFIRST);  SPI.setDataMode(SPI_MODE3); //I believe it to be Mode3  SPI.setClockDivider(SPI_CLOCK_DIV16);  pinMode(SS, OUTPUT); //not really necessary as it is done by the SPI library.  digitalWrite(SS, HIGH);  //Page  //example of reading data  unsigned long voltage = SPI_read(4);//Instantaneous Voltage Channel 1    //example of writing data  union FourByte data;  data.command = 0b01000000; //Write to config register  data.value = 1; //This is the default value from datasheet, just using it as an example.  SPI_write(data);}void loop(){  }void SPI_write(union FourByte data) {  digitalWrite(SS,LOW); //Using CS pin, so sync1/sync0 bytes not needed  for(char i = 3; i >= 0; i--){    SPI.transfer(data.bit8[i]); //transfer all 4 bytes of data - command first, then Big Endian transfer of the 24bit value.  }  digitalWrite(SS,HIGH);}unsigned long SPI_read(byte command){  digitalWrite(SS,LOW); //SS goes low to mark start of transmission  union FourByte data = {0xFEFEFE,command}; //generate the data to be sent, i.e. your command plus the Sync bytes.  for(char i = 3; i >= 0; i--){    data.bit8[i] = SPI.transfer(data.bit8[i]); //send the data whilst reading in the result  }  digitalWrite(SS,HIGH); //SS goes high to mark end of transmission  return data.value; //return the 24bit value recieved.}
 783 Using Arduino / Microcontrollers / Re: SPI read write for 32bits data on: November 19, 2012, 01:36:39 pm You can use a 'union' to efficiently and quickly convert a long to a series of four bytes or 2 ints or vice versa:Code:#include union FourByte{    unsigned long bit32;    unsigned int bit16[2];    unsigned char bit8[4];};void setup(){  SPI.begin();    //save a 32bit value  unsigned long someValue = 0xFFFFFFFEUL;  //transmit 32bit value:  transfer(someValue);    //read 32bit value  someValue = transfer(0);    //read and write at the same time.  someValue = transfer(someValue);  //concatinate ints:  FourByte bob;  bob.bit16[0] = 10;  bob.bit16[1] = 20;    transfer(bob.bit32); //sends 1310730 = 20*65536+10  //concatinate bytes:  bob.bit8[0] = 0x1; //1  bob.bit8[1] = 2; //2  bob.bit8[2] = 0b11; //3  bob.bit8[3] = B100; //4    transfer(bob.bit32); //transfers 0x04030201}unsigned long transfer(unsigned long value){  FourByte data = {value};  for(byte i = 0; i < 4; i++){    data.bit8[i] = SPI.transfer(data.bit8[i]);  }  return data.bit32;}
 784 Using Arduino / Programming Questions / Re: Arduino capacitor reformer on: November 18, 2012, 05:20:00 am Quote from: MarkT on November 18, 2012, 04:52:27 amCode:  if (state = 1) int charge ();  if (state = 2) int wait (hold);  if (state = 3) int discharge ();  if (state = 4) int saftey ();isn't right.  Are you expecting to call some functions rather than declare them?Your code sounds like it can simply be linear and not need a state variable (or are you doing something else in the sketch at the same time?)Not only that, but they should all be the equality operator ('==') not the assignment operator ('=').
 785 Using Arduino / Programming Questions / Re: what's means about "PINB |= 1<<5" on: November 17, 2012, 03:53:03 pm I believe your understanding is correct.A bit of background (I am using I/O to mean a physical pin on the chip to avoid confusion with the PIN register).There are 3 registers that control any given I/O on the chip:PIN = input registerPORT = output registerDDR = direction register.The direction register controls whether an I/O is an input or an output. Behind the scenes pinMode(pin); uses this register.The input register is what you use to read the current state of the I/O. If the I/O is an input PIN returns the value of whatever is connected, if it is an output, PIN returns the value in PORT.The output register is what you use to set the state of an I/O. If the I/O is an output, PORT sets it to be a 1 or a 0. If the I/O is an input, PORT sets whether or not the internal pullup is enabled.If the DDR register is set to Output, and you try to write to the PIN register, the I/O toggles such that if the output state is a 1, it becomes a zero and vice versa.
 786 Using Arduino / Programming Questions / Re: What is wrong with this code? on: November 17, 2012, 03:40:36 pm You may have to type cast it:Code:strsep ((char**)&data, "M");or if you don't want to type cast you could do:Code:char data[] = "whatever";char* ptr = data;strsep(&ptr,"M");
 787 Using Arduino / Programming Questions / Re: What is wrong with this code? on: November 17, 2012, 03:04:00 pm The same way you did before:Code:&data'data' is just a pointer to the start of an array, and in this case the array is of type char, so 'data' a char*As a side note, when you access an element of an array, you are essentially saying 'get the value stored at the pointer to the start of the array plus some offset'. e.g.:data[0] is the same as *datadata[1] is the same as *(data + 1)data[2] is the same as *(data + 2)and so on.
 788 Using Arduino / Programming Questions / Re: what's means about "PINB |= 1<<5" on: November 17, 2012, 02:55:03 pm Writing a logic 1 to a bit in the PINx register of many atmegas results in the corresponding output toggling its state.In this case, arduino pin 13, corresponds to the atmega PORTB bit 5. So writing a 1 to PINB bit 5 toggles the pin.
 789 Using Arduino / Microcontrollers / Re: Arduino Tiny on: November 16, 2012, 03:34:03 am I found a reference to the arduino core in the platforms.txt file which should be 'tiny'. I have change that and attached it.I'm not having any problems with 1.5.0, though it seems in 1.5.1 they changed how the menu's work so the diving of boards into submenus that I had done doesn't work anymore. Other than that though all is well (maybe its because I have a different core? though there shouldn't be an issue with that from the IDEs point of view).
 790 Using Arduino / Microcontrollers / Re: core13: An Arduino core for the Attiny13 *testers wanted* on: November 13, 2012, 09:05:54 am An attiny2313 is not an attiny13. Thus their unique device signatures don't match.
 791 Using Arduino / Microcontrollers / Re: Arduino 1.0.2 & ATtiny 85 on: November 12, 2012, 06:27:15 pm Quote from: bperrybap on November 12, 2012, 05:12:08 pmgcc only compiles what it is told to compile. The IDE is the one that tells gcc what to compile. Post edited
 792 Using Arduino / Microcontrollers / Re: Arduino 1.0.2 & ATtiny 85 on: November 12, 2012, 04:17:45 pm Thats because it is compiling the wrong core.you should be seeing it compile filed at:D:\Arduino\arduino-1.0.2\hardware\arduino\cores\tiny\Have you downloaded the Tiny core? The Arduino core is not suitable for attiny's.As for blink including the IPAddress files, when the IDE uses gcc to compile the program, it tells it to compile all files in the core. If you don't include the associated header files (or cpp files themselves) anywhere in your code, the files and code associated will be scrubbed by the linker.
 793 Using Arduino / Displays / Re: SPI 0.96" Color OLED Display Wiring on: November 10, 2012, 01:35:17 pm FETs = Transistors.A lot of ebay auctions say "Arduino Compatible". In many cases that just means that an arduino and it can be hacked together in such a way that it works. In many cases that hacking is just a level shifter, or getting a 3.3v arduino.You will need the (logic) level shifter otherwise you will most likely damage the display.
 794 Using Arduino / LEDs and Multiplexing / Re: Why do LEDs explode? on: November 10, 2012, 01:31:03 pm *Silicon Actually more likely GaAs/InGaAs/InGaP/etc rather than Silicon - Silicon isn't good at producing light, but that is a whole different kettle of fish.
 795 Using Arduino / LEDs and Multiplexing / Re: Why do LEDs explode? on: November 10, 2012, 11:54:32 am As you try and force more and more electrons to flow through the diode (i.e. a higher current), more energy is dissipated in the semiconductor due to collisions between the electrons and the lattice structure of the semiconducter material. The heat causes the lattice to gain energy and expand.The plastic doesn't expand as much and so pressure builds up inside the LED until the plastic fails and cracks at which point all the energy stored up pressing against the inside of the shell is rapidly dissipated in the form of pressure waves (sound) and kinetic energy (the bits of plastic launching across the room).Granted that is a catestrophic failure. In many cases the failure will not be catestrophic, but rather simply the fragile metal wire interconnects will melt rather like a fuse does. Though either way the final outcome is the same... you have to buy a new LED  .
 Pages: 1 ... 51 52 [53] 54 55 ... 106