Show Posts
Pages: [1] 2
1  Using Arduino / Displays / Re: ST7920 multiple SPI device problems on: November 11, 2013, 07:26:34 pm
That seems to have done it!  I just had to use the HW spi mode and I needed to be a careful about the order I initialize things in.  Thanks so much!!!
2  Using Arduino / Displays / Re: ST7920 multiple SPI device problems on: November 11, 2013, 06:11:40 pm
Just tried it, I just get a massive array of random chinese characters.  Doesn't seem to help.  Think this might be an issue with me not using an Arduino Mega?

As far as I can tell, this issue is directly related to adding the SD card initialization into the code.  The datasheet mentions that 'transients' cannot be present on the communication lines even when the CS is off. 
3  Using Arduino / Displays / Re: ST7920 multiple SPI device problems on: November 11, 2013, 04:36:33 pm
Here's a picture of what happens:  http://bayimg.com/iacEGaAfe
4  Using Arduino / Displays / ST7920 multiple SPI device problems on: November 11, 2013, 04:31:02 pm
Hello,  I'm currently working on a project where I read in a bunch of thermistors and current sensors and use that information to control a set of relays.  It's for a residential heating application where solar heated water is being used to warm the house.

The problem  I am having is that I can't get the ST7920 screen that I'm using (http://www.robotshop.com/ca/en/dfrobot-spi-lcd-module-arduino-compatible.html#Useful Links) to work reliably when other devices are communicating on the SPI line.   As soon as I initialize the SD card the screen starts to display random Chinese characters and I can't figure out why this is happening.  

The u8glib library mentions something about the SPI communication being on software mode and that other devices use hardware SPI.  However, I use the 'u8g.setHardwareBackup(u8g_backup_spi);' function that I think should fix this.

Any ideas on how to fix this would be greatly appreciated.  Right now I'm thinking that I might have to set up a little logic gate on the MOSI pin of the screen so that is the CS pin for the screen is off the sceen won't receive any communications.  However, I'd expect there to be a way of fixing this in software.

Thanks!

Andre

Code:
#include <U8glib.h>
#include <SD.h>

const int CS_ST7920 = 8; //chip select for Screen   (LOW = OFF)
const int CS_SD = 4;     //chip select for SD card (HIGH = OFF)?

boolean card_state = 0; //0 = sd card failure

String PRINT_ME = "Hello Screen";

U8GLIB_ST7920_128X64_1X u8g(13, 11, CS_ST7920);

void setup()
{
   delay(100);
   
   //Initalize chip select pins
    pinMode(SS, OUTPUT);
    pinMode(CS_ST7920, OUTPUT);
    pinMode(CS_SD, OUTPUT);
   
    //Default to having the device communication lines turned off
    digitalWrite(CS_ST7920, LOW); 
    digitalWrite(CS_SD, HIGH);
   
    //Initalize Screen
    u8g.begin();
    delay(50);
    u8g.setHardwareBackup(u8g_backup_spi);
    delay(50);
   
    //Initalize SD card
  Serial.begin(9600);
  if (!SD.begin(CS_SD)) {
    card_state = 0;
    Serial.println("card failed!");
  }else{
    card_state = 1;
    Serial.println("card initialized.");
  }
}

void loop()
{

  write_info();
 
}

//===============================================================
// SCREEN DRAW
//===============================================================

void write_info(void) {
  // picture loop
//    st7920_init();
//    delay(50);
  u8g.firstPage(); 
  do {
    draw();
  } while( u8g.nextPage() );
 
  // rebuild the picture after some delay
  delay(500);
}



void draw(void) {
  // graphic commands to redraw the complete screen should be placed here 
  u8g.setFont(u8g_font_unifont);
  u8g.setPrintPos(0, 20);
  // call procedure from base class
  u8g.print(PRINT_ME);
  delay(100);
  digitalWrite(CS_ST7920, LOW);
}

5  Using Arduino / Storage / Re: Fast microSD code modification on: June 14, 2012, 08:11:20 am
I received this reply (hope this might be of help to someone in the future):

"Wire uses interrupts so it won't work well with the fastLogger examples which read data in interrupt routines.... People have logged data from accelerometers at high speed using SdFat but from SPI based devices."

So it looks like I just need to communicate with the adxl345 through SPI to get the higher sampling rates.
6  Using Arduino / Storage / Fast microSD code modification on: June 13, 2012, 07:44:40 pm
Hello,

I've been modifying code developed by Fat16lib (it can be found here) http://code.google.com/p/beta-lib/downloads/list under fastLoggerBeta20110802.zip 

Basically, I am doing a project where I am looking to write acceleration values from an adxl345 accelerometer to an SD card as fast as possible (at least 1500 samples per second without dropping data points).  The code presented in the link under 'fastlogger.pde' seems to do this quite well.  However, I am having a great deal of trouble modifying the example code to get it to write my data.

So this is what I have (from the example code):

Code:
// I2C binary logger example

#include <Wire.h>
#include <SdFat.h>
#include <SdFatUtil.h>

SdFat sd;

SdFile file;

#define error(msg) sd.errorHalt_P(PSTR(msg))
//------------------------------------------------------------------------------
bool over = false;
//------------------------------------------------------------------------------
const uint16_t RING_DIM = 600;
uint8_t ring[RING_DIM];
volatile uint16_t head = 0;
volatile uint16_t tail = 0;
uint32_t syncCluster = 0;
//------------------------------------------------------------------------------
// buffer data from I2C
void receiveEvent(int howMany) {
  for (int i = 0; i < howMany; i++) {
    ring[head] = Wire.receive();
    uint16_t next = head < (RING_DIM - 1) ? head + 1 : 0;
    // check for space
    if (next != tail) {
      // space so advance head
      head = next;
    } else {
      // can't advance head so data is dropped
      over = true;
    }
  }
}
//------------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  Serial.println("Type any character to start");
  while (!Serial.available());
  Serial.print("FreeRam: ");
  Serial.println(FreeRam());
 
  if (!sd.init()) sd.initErrorHalt();
  if (!file.open("I2C_TEST.TXT", O_WRITE | O_CREAT | O_TRUNC)) error("open");
  file.print("Start ");
  file.println(millis());
  file.sync();
 
  syncCluster = file.curCluster();
  Serial.println("Started - type any character to stop");
  Serial.flush(); 

  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
}
//------------------------------------------------------------------------------
void loop() {
  uint16_t n;
  uint16_t next;
  // disable interrupts to get 16-bit head
  cli();
  uint16_t h = head;
  sei();
 
  if (h != tail) {
    if (tail < h) {
      // amount to write
      n = h - tail;
      // new tail
      next = h;
    } else {  // h < tail
      // amount to write
      n = RING_DIM - tail;
      // new tail
      next = 0;
    }
    if (file.write(&ring[tail], n) != n) error("write");
    cli();
    tail = next;
    sei();
  }
  if (file.curCluster() != syncCluster) {
    if (!file.sync()) error("sync");
    syncCluster = file.curCluster();
  }
  if (!Serial.available() && !over) return;
  cli();
  file.print("Stop ");
  file.println(millis());
  file.close();
  if (over) error("overrun");
  Serial.println("stoped");
  while(1);
}

And this is my function that I use (in a slower datalogger) to get the data from teh ADXL345:

Code:
// Reads x,y and z accelerometer registers
void Read_Accel()
{
  int i = 0;
  byte buff[6];
 
  Wire.beginTransmission(AccelAddress);
  Wire.send(0x32);        //sends address to read from
  Wire.endTransmission(); //end transmission
 
  Wire.beginTransmission(AccelAddress); //start transmission to device
  Wire.requestFrom(AccelAddress, 6);    // request 6 bytes from device
 
  while(Wire.available())   // ((Wire.available())&&(i<6))
  {
    buff[i] = Wire.receive();  // receive one byte
    i++;
  }
  Wire.endTransmission(); //end transmission
 
    if (i==6){  // All bytes received?
       accel_x = (((int)buff[1]) << 8) | buff[0];    // X axis (internal sensor x axis)
       accel_y = (((int)buff[3]) << 8) | buff[2];    // Y axis (internal sensor y axis)
       accel_z = (((int)buff[5]) << 8) | buff[4];    // Z axis
     }else{
       Serial.println("!ERR: Error reading accelerometer info!");
     }
}

So I can load my data in, I'm just not sure how to get it into the example code (what variable to assign it as, etc) so that it gets uploaded to the SD card.

Any advice would be greatly appreciated.

Cheers,

Andre
   
7  Development / Other Hardware Development / pro mini conversion on: August 22, 2011, 05:25:57 pm
Hi there,

I'm looking to convert a couple of 5v pro mini's to 3.3v pro mini's.  I figure I'll have to swap the regulators, the bootloaders and the oscillators.  I am just wondering if anyone knows the part number for the 8 mHz oscillators as I can't seem to find a compatible one.

Also I think I found something that might work but it's listed as a resonator in digikey.  But what is the difference between a crytal, an oscillator and a resonator (from a google search it looks like and oscialltor is just a crystal with the control capacitors, but I may be wrong).

Cheers,

Andre
8  Using Arduino / Storage / Re: 3v3 pro mini interfacing to SD bug - SOLVED on: August 09, 2011, 04:03:59 pm
So.... It actually looks like the issue was that I wasn't grounding the SD card!  It blows my mind as the board was a revision of an earlier one so I never thought to think of it.

Programs like SDinfo were even returning information about the card, despite the fact that it wasn't grounded.  I honestly can't believe that that one version of SD card was actually able to run without a ground!

Needless to say I feel like I learned a thing or two on that one  smiley-red
9  Using Arduino / Storage / Re: 3v3 pro mini interfacing to SD bug on: July 19, 2011, 05:02:15 pm
So I've found a fix though it is a bit sloppy.

Basically I went to a shop and bought every 2gb microSD card they had then tested them to see if it was a card issue.

All the cards continued to fail except for a DANE-ELEC 2 gb card, which is working flawlessly. 

So I didn't find or figure out what is causing the issue but fortunately I've found an acceptable work around.

So far I've used:
Jony 1gb - From sparkfun - FAILED
Unnamed 1 gb - From sparkfun - FAILED
Kingston 2gb -FAILED
NEXXTECH 2gb - FAILED
DANE-ELEC 2 gb - WORKS!! (also the cheapest card being sold)

10  Using Arduino / Storage / Re: 3v3 pro mini interfacing to SD bug on: July 19, 2011, 01:23:39 pm
I just tried re-burning the bootloader onto the arduino and powering the device via the FTDI breakout.  No luck, though if I boost the voltage to 5 volts it works.  I'm very confused at this point as I feel like I have tried almost every possibility.  Would you have some example code I could examine that you use with the 3.3 volt pro mini.  Right now I'm looking into if there is an issue with the SPI_FULL_SPEED writes.
11  Using Arduino / Storage / Re: 3v3 pro mini interfacing to SD bug on: July 19, 2011, 12:28:18 pm
Hey there,

I've run SDinfo.pde and this is what I got:

Quote
type any character to start

card.init failed
SD errorCode: 0X8
SD errorData: 0X1

type any character to start

init time: 6 ms

Card type: SD2

Manufacturer ID: 0X4
OEM ID: A
Product: SMI-S
Version: 4.4
Serial number: 3
Manufacturing date: 6/2001

cardSize: 1024 (512 byte blocks)
flashEraseSize: 32 blocks
eraseSingleBlock: false
read MBR failed
SD errorCode: 0XF
SD errorData: 0XFF

I think it is really weird that the first run fails yet the following runs work!

The card is a 1GB SDmicro from sparkfun

I've played around with powering the device and it works if I supply the 4 volts raw to the arduino (on the Vcc pin) with the sd card running off the regulated 3.3volts but it doesn't work if I give the arduino 3.3 volts and the sd card power the 4 volts. 

I just ran a test where I used a high quality lab power supply to supply the 3.3 volts to the arduino (vcc) and SD card.  The board would not communicate and yet when the voltage was raised to 5 volts it would communicate (dropping out at 4 volts).

Therefore I have to conclude that there is some strange glitch on the arduino as it will not communicate at voltages below 4 volts even though it is a 3.3 volt board.  Communication is fine if the SD card is supplied with 3.3 volts and if only the arduino is at the higher voltage.  I built up a second circuit to see if this was a one off error but both boards have the same issue (maybe I bought from a bad batch, though the sketches upload fine).  I am currently checking to see if uploading a new bootloader will help.

PS Those faster data loggers sound really interesting!

Any suggestions for brands of SD cards that have a good reputation?

12  Using Arduino / Storage / Re: 3v3 pro mini interfacing to SD bug on: July 18, 2011, 03:08:27 pm
It has 100 mA with a good selection of capacitors on it (.47uF, 1uF, 47uf).

I believe this is more then enough for an SD card and an arduino (about 20 mA + 20 mA) the accelerometer uses about 60 uA i believe.

Cheers
13  Using Arduino / Storage / Re: 3v3 pro mini interfacing to SD bug on: July 18, 2011, 02:59:51 pm
To avoid dropping data points I only sync once large sets of data are collected.  Though during the syncing process some data points are lost.

PIN 10 is connected directly to CS
PIN 11 is connected directly to DI
PIN 12 is connected directly to DO
PIN 13 is connected directly to SCLK

As the arduino runs on 3.3 volts these are direct connections with no pull up or pull down resistors.

Cheers
14  Using Arduino / Storage / 3v3 pro mini interfacing to SD bug - SOLVED on: July 18, 2011, 02:08:42 pm
Hi there,

I am working on a project taking an X,Y and Z reading from an adxl335 accelerometer using the onboard ADC and am storing those values to an SD card at 500 Hz.  I've had the code working on a 5v pro mini but recently switched to a 3v3 pro mini do to simplicity (not needing to step up the 3.7 volts from the battery to 5v).  However, the 3v3 pro mini will not recognize the SD card!  It returns errors about the format.

However, if I run the SD card on 5 volts (I did this by accident) it works fine and writes to the SD card fine.

Has anyone run into this before, or have any ideas about where to look?

Below is my code though it will work fine on a 5 volt board or when the 3v3 board is powered with 5 volts:

Code:
/*
 * This sketch is a simple binary write/read benchmark.
 */
#include <SdFat.h>
#include <SdFatUtil.h>

//String r32 = "zz";
int vx = 0;
int vy = 0;
int vz = 0;
int r1 = 0;
int r2 = 0;

const int flasher = 9;
uint32_t m;
unsigned long LOG_INTERVAL;
unsigned long TWO_LOG;

char lookup32[] =
{
  '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V'
};
// 0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31


// SD chip select pin
const uint8_t chipSelect = SS_PIN;

// text file for logging
ofstream logfile;

#define FILE_SIZE_KB 12
//SET TO 24 before sending out


#define SAMPLES_PER_SECOND 2  // mills between entries
#define FILE_SIZE (1000UL*FILE_SIZE_KB)

#define BUF_SIZE 8

uint8_t buf[BUF_SIZE];

SdFat sd;

SdFile file;

ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
// store error strings in flash to save RAM
#define error(s) sd.errorHalt_P(PSTR(s))
//------------------------------------------------------------------------------

void createbuffer()
{
  
  // fill buf with known data
//   delay(10);
  vx = analogRead(A2);  // 230us per line - X chan
//   delay(10);
  
  base32(vx);
  buf[BUF_SIZE-8] = lookup32[r2];
  buf[BUF_SIZE-7] = lookup32[r1];
  
//   delay(10);
  vy = analogRead(A1);  // Y read
//   delay(10);
  
  base32(vy);
  buf[BUF_SIZE-6] = lookup32[r2];
  buf[BUF_SIZE-5] = lookup32[r1];
  
//  delay(10);
  vz = analogRead(A0);  // Z read
//   delay(10);
  
  base32(vz);
  buf[BUF_SIZE-4] = lookup32[r2];
  buf[BUF_SIZE-3] = lookup32[r1];

  buf[BUF_SIZE-2] = '\r';
  buf[BUF_SIZE-1] = '\n';
  
  return;
}


void base32(int number)
{
  
  int n1 = int(number/32);
   r1 = number - 32 * n1;
  int n2 = int(n1/32);
   r2 = n1 - n2;

  return;
}


void setup() {
  Serial.begin(9600);
  
  pinMode(flasher, OUTPUT);
  digitalWrite(flasher, LOW);
  
  if (!sd.init(SPI_FULL_SPEED, chipSelect)) sd.initErrorHalt();
  
  char name[] = "LOG00.TXT";

  for (uint8_t i = 0; i < 100; i++) {
    name[3] = i/10 + '0';
    name[4] = i%10 + '0';
    if (sd.exists(name)) continue;
       file.open(name, O_CREAT | O_TRUNC | O_RDWR);
    break;
  }
}
//------------------------------------------------------------------------------
void loop()
{
 // do write test
  uint32_t n = FILE_SIZE/sizeof(buf);

  for (uint32_t i = 0; i < n; i++) {
    digitalWrite(flasher, HIGH);
    createbuffer();
    digitalWrite(flasher, LOW);
    delayMicroseconds(955); //Controls 500Hz Sampling Rate    

    
    if (file.write(buf, sizeof(buf)) != sizeof(buf)) {
      error("write failed");
    }
  }

  file.sync();
 
}
15  Using Arduino / Storage / Re: Urgent: SD card write speeds on: June 13, 2011, 09:16:18 am
As a followup to this thread.  I was able to get the write speeds I needed by modifying the 'bench' example provided with the sdfat library to write what I wanted.  It basically did what everyone was suggesting with writing larger chunks of data, though it was nice having an example as my programming skills are weak. 

In the future I hope to get into the example code that Aeturnalus provided as it looks to be much much more efficient then what I am doing now.

Cheers, and thanks for all the help everyone!
Pages: [1] 2