Show Posts
Pages: 1 ... 54 55 [56] 57 58 ... 116
826  Using Arduino / General Electronics / Re: SFE microSD Breakout woes ... on: January 07, 2013, 05:16:10 am
The begin() function calls card.init() with SPI_HALF_SPEED:

boolean SDClass::begin(uint8_t csPin) {

    Performs the initialisation required by the sdfatlib library.

    Return true if initialization succeeds, false otherwise.

  return card.init(SPI_HALF_SPEED, csPin) &&
         volume.init(card) &&

Which means it is running too fast. In Windows, if you open the following file (it is slightly different on Mac):
<arduino directory>/libraries/SD/SD.cpp

You will find the begin() function declaration, just change the SPI_HALF_SPEED to 2.

As for the TXB0104, there are breakout boards available ready soldered: (This is actually the 8 channel version, TXB0108),-level-shifter,-3v/5v,-14-pin-wide-dip.html (4 channel TXB0104)
827  Using Arduino / Project Guidance / Re: Speedy line follower ( Due/ Raspi/Launchpad, which to use?) on: January 06, 2013, 07:18:17 pm
You wouldn't use the Raspberry Pi for something like that. It runs linux, which is not a real time operating system.
828  Using Arduino / General Electronics / Re: SFE microSD Breakout woes ... on: January 06, 2013, 07:11:07 pm
A sudden thought occured

Try changing this line:
 if (!card.init(SPI_HALF_SPEED, chipSelect)) {
 if (!card.init(6, chipSelect)) {

That will slow down the SPI to the slowest possible speed of FCPU/128

If that works, try decreasing the number to 5, then 4, then 3 and so on. Each time it will double the speed.

With simple level converters like these, I was never able to get it to run faster than FCPU/8 (aka SPI_QUARTER_SPEED) reliably. Once i switched to a proper level shifter like the TXB0104, I could get up to the full speed of FCPU/2 (aka SPI_FULL_SPEED).

Just as a side note, the card.init() call initialises the card at FCPU/128, and then at the end of the routine sets it to full speed. This means that the volume.init() call will be running on a an SPI at a much higher freqency than card.init() which could be the reason why it fails at that point.
829  Using Arduino / Microcontrollers / Re: Arduino with Atmega32A core on: January 06, 2013, 04:40:14 pm

$7 doesn't seem that bad for an Atmega1284P. Its £3.80 here in the UK.
830  Using Arduino / Displays / Re: ARDUINO 4DISPLAY SHIELD 160 on: January 06, 2013, 04:29:35 pm
The message to take away from the comment it, first thing to do is Google it...

Second result any good?

There is a minor issue with that library in that it doesn't support Arduino 1.0+, but you can make it supporting by opening the file "displayshield4d.cpp" and replacing the line:
#include "WProgram.h"
with the line:
#include "Arduino.h"
831  Using Arduino / Displays / Re: lcd.print and lcd.write at one line on: January 06, 2013, 04:24:00 pm
If you don't want to convert to Octal, you can add letters in hex:
char string[] = "\x30\x31\x32";
is equivalent to:
char string[] = "123";
is equivalent to (octal):
char string[] = "\060\061\062";
832  Using Arduino / General Electronics / Re: SFE microSD Breakout woes ... on: January 06, 2013, 04:18:47 pm
If I were you, I would swap which level shifter you are using for DI and CS.

DI <- TXI (ch2) <- TXO (ch2) <- MOSI
CD <- RXO (ch2) <- RXI (ch2) <- pin4

Goodness knows why Sparkfun gave the signals the names they did  smiley-roll. Basically the mosfet shifter is bidirectional, but it will perform better than the resistor divider and is better suited to the data line, or even better still the clock line, for example:

DO -> TXI (CH1) on LV side -> TXO (CH1) on HV side -> MISO on Uno
SCK <- TXI (ch2) on LV side <- TXO (ch2) on HV side <- SCK on Uno
VCC <- 3.3V on Uno
DI <- RXO (CH1) on LV side <- RXI (CH1) on HV side <- MOSI on Uno
CS <- RXO (ch2) on LV side <- RXI (ch2) on HV side <- pin 4 on Uno
833  Using Arduino / Programming Questions / Re: Why does this work in a .h but not in a .ino? on: January 06, 2013, 02:47:59 pm
Does this mean that every function prototype I have in an .ino file is worthless and always get's superseded by one created by the IDE?

Wrong! The IDE only creates prototypes for functions in the .ino which do not already have one.

void doState1()
  //..some code  same with 2 and 3
void doState2()
  //..some code
void doState3()
  //..some code

typedef void (*S_Function)();

S_Function State_Functions[] = {
  &doState1, &doState2, &doState3};

S_Function getCallback(int _state); //create function prototype here, and the IDE wont add one at the top.
S_Function getCallback(int _state)
  return State_Functions[_state];

834  Using Arduino / Programming Questions / Re: Can someone help me figure out what this loop is doing? on: January 06, 2013, 02:44:55 pm
If the card did return 0, then you would get:

0x00 & 0x80 = 0 = false, which means the loop would be broken.
835  Using Arduino / Programming Questions / Re: Tick Tock Another Binary Clock on: January 06, 2013, 12:53:32 pm

I have just noticed you are trying to have the clock automatically turn off the display, then turn it back on when the user presses a switch or something. In which case use method (1) or (2) of those i mentioned in the last post. If you make the external resistor something like 10k to 100k.
836  Using Arduino / Programming Questions / Re: Tick Tock Another Binary Clock on: January 06, 2013, 12:48:24 pm
Basically to trigger the uC to wake up, you have to cause an interrupt. To make a pin change interrupt occur, you need to simply toggle the logic state of the pin.
You can do that in a number of ways:
(1) add an external pullup resistor, then to wake up, simply pull the pin to ground with a switch.
(2) add an external pulldown resistor, then to wake up, simply connect the pin to +5v with a switch.
(3) If you went for a DS1307 based RTC, then you could connect its SQW output to Digital 0, and configure the DS1307 to output 1Hz. That way the microcontroller gets woken up once every second.

The third method would seem to me to be an ideal solution. You can put the arduino to sleep. Then when it is woken back up by the DS1307, you can read in the current time, output it to the clock display, then put the arduino back to sleep.
That way the arduino would sleep saving power for most of the time, but the clock would update once every second. You could probably accomplish reading in the time and updating the clock within a few milliseconds, meaning the arduino would sleep for about 99% of the time.
837  Using Arduino / LEDs and Multiplexing / Re: LED cube,shift registers and fun. on: January 06, 2013, 11:27:41 am
I think I am right in saying that there is an important omission from the example you posted.
void myMethod(){
    char buffer* = malloc(256);
    for(int I=0; I<256;I++){
   //When the function returns, the 'buffer' memory remains allocated, but the pointer to this memory is lost.
   //As nothing now knows the address of the allocated memory, nothing can use it. This is known as a memory leak.
Should be:
void myMethod(){
    char buffer* = malloc(256);
    for(int I=0; I<256;I++){
    free(buffer); //free the memory otherwise there is a memory leak.
838  Using Arduino / Programming Questions / Re: Tick Tock Another Binary Clock on: January 06, 2013, 09:07:10 am
According to the datasheets, Pin change interrupts can be used to wake from sleep, which means you can use Digital Pin 0 to wake from power down and sleep modes.
Digital0 is PCINT16 (pin change interrupt source 16). Which means its interrupt can be enabled with:
 PCMSK2 = _BV(0); //set PCINT16 as enabled, others disabled
  PCICR |= _BV(2); //enable pin change interrupt source 2.

And disabled with:
 PCICR &= ~_BV(2); //disable pin change interrupt source 2.

And if needed, the corresponding interrupt routine is:
  //code executed on pin change.
839  Using Arduino / Microcontrollers / Re: Reset flags in MCUSR not mutually exclusive? on: January 04, 2013, 06:57:29 pm
As an example, this is at the start of my modified optiboot:

  ch = MCUSR;
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__)
  if (!(ch & (_BV(EXTRF) | _BV(PORF)))) appStart(); //Power on reset loads bootloader as well - allows bootloader even if reset pin is disabled //(1)
  if (!(ch & _BV(EXTRF))) appStart(); //(2)

The normal optiboot just (2), which says that if the reset button was pressed, run the bootloader, otherwise skip the bootloader.
I added (1) which means that in the event of a power-on reset, the bootloader still runs - this is because I needed optiboot to work on an attiny with the reset pin disabled so EXTRF could never be set.
840  Using Arduino / Microcontrollers / Re: Messed up some fuses on: January 04, 2013, 02:26:36 pm
Fortunately it looks like you haven't disabled SPI or the reset pin.

You have however selected 'External Clock' as the oscillator which means you cannot at the moment use a crystal.

What you need to do is remove the crystal (carefully so you can put it back on later), and feed a clock signal into XTAL1 (Pin1 of the IC). The clock will need to be say 8MHz. It may be possible to feed the clock signal in to Pin1 without removing the crystal, so you might want to try it before removing the crystal.
I have attached a picture which shows a place where you can solder a wire on to the board to get access to pin 1.

If you have a spare arduino which can still be programmed with via USB, you can use that to provide a clock signal. Alternatively you can burn new fuse settings into the Atmega328 that is on the board to output its system clock and feed that output into the 8u2.

Once you have got a clock source into the chip, you can use ISP to correct the fuse settings. I believe the correct settings for the 8u2 are:
Low = 0xFF
High = 0xD9
Extended = 0xFF (or 0xCB if you want brown out enabled)
Pages: 1 ... 54 55 [56] 57 58 ... 116