Show Posts
Pages: [1] 2 3 4
1  Using Arduino / LEDs and Multiplexing / Re: Rainbowduino drawLine - please explain on: November 02, 2013, 02:32:39 am
On the second thought, it's probably 'a feature'.
Seems like this is a simplest implementation of Bresenham valid only for one octant where x1>x0 and y1>y0
Grabbed from
http://groups.csail.mit.edu/graphics/classes/6.837/F99/grading/asst2/turnin/rdror/Bresenham.java:
Code:
void drawLine2(int x0, int y0, int x1, int y1, uint32_t color)
{
  boolean xy_swap=false;
  if (abs(y1 - y0) > abs(x1 - x0)) {
    xy_swap = true;
    int temp = x0;
    x0 = y0;
    y0 = temp;
    temp = x1;
    x1 = y1;
    y1 = temp;
}
// If line goes from right to left, swap the endpoints
   if (x1 - x0 < 0) {
    int temp = x0;
    x0 = x1;
    x1 = temp;
    temp = y0;
    y0 = y1;
    y1 = temp;
    }
 
  int x,                   // Current x position
  y = y0,                  // Current y position
  e = 0,                   // Current error
  m_num = y1 - y0,         // Numerator of slope
  m_denom = x1 - x0,       // Denominator of slope
  threshold  = m_denom/2;  // Threshold between E and NE increment

  for (x = x0; x < x1; x++) {
    if (xy_swap)
Rb.setPixelXY(y,x,color);
    else Rb.setPixelXY(x,y,color);
  e += m_num;
    // Deal separately with lines sloping upward and those
    // sloping downward
   if (m_num < 0) {
if (e < -threshold) {
    e += m_denom;
    y--;
}
    }
    else if (e > threshold) {
e -= m_denom;
y++;
    }
  }
  if (xy_swap)
    Rb.setPixelXY(y,x,color);
  else Rb.setPixelXY(x,y,color); 
}
This seems to be working correctly.
2  Using Arduino / LEDs and Multiplexing / Rainbowduino drawLine - please explain on: November 02, 2013, 01:49:44 am
I use library Rainbowduino 3.0 with Rainbowduino shield and common anode RGB LED matrix 8x8
Code:
drawLine(0,0,7,7,<color>)
draws diagonal line.

But why
Code:
drawLine(0,7,7,0,<color>)
draws horizontal line,
exactly as
Code:
drawLine(0,7,7,7,<color>)
?

I s this a bug or a feature?
3  Using Arduino / Project Guidance / Re: olimex ekg on: December 24, 2012, 04:14:54 pm
Just FYI, I posted some of my results with ECG shield  on OLIMEX forum:
https://www.olimex.com/forum/index.php?topic=572.0

As per displaying ECG on LCD, I'd rather go for smthng like Processing application ECG viewer; tiny LCD screen would not reflect any additional information on ECG shape. And also, keep in mind that the cable they provide is of very low quality, so you should not expect good result from it. ECG picture they give in .pdf <somethingGURU> application - I don't know how they actually produced such an image.
4  Using Arduino / Sensors / Re: How to connect piezo accelerometer? on: December 14, 2012, 12:18:01 pm
Thanks a lot for your help, dc42!
Now it really works,
 so I am acquiring and storing about 28000 points/sec with Arduino Mega.
5  Using Arduino / Sensors / Re: How to connect piezo accelerometer? on: December 13, 2012, 04:41:36 pm
So it should be something like this?


I don't quite understand why do I need R1 at all? It's not a part of high pass filter, right?
Is it something related to high output impedance of the sensor?
6  Using Arduino / Sensors / Re: How to connect piezo accelerometer? on: December 13, 2012, 04:28:24 pm
dc42, thank you for the prompt response!
this is my current connection:

Resistors are 15k (left) and 150k (right), capacitor 0.33 mF
With this setup I can only see positive accelerations.
What should i change to see both negative and positives?
May be, I should connect R1 and R2 not to the Gnd, but to something like +2v from simple voltage divider?
7  Using Arduino / Sensors / How to connect piezo accelerometer? on: December 13, 2012, 03:03:21 pm
I am trying to read  piezo accelerometer ACH-01 data with Arduino;
I am confused with interface circuit it requires. Data sheet says it need biased power supply and provides a simple schematic with -5V/+5V supply; there is another uni-polar alternative with two op-amps;
Is there any simpler way to interface Arduino with this accelerometer?
If I connect it to Gnd, +5V and to analog ping through RC high pass filter, it shows accelerations, but only top half of acceleration wave - I vaguely understand it has something to do with that biasing.
Another thing I don't understand about it - why it requires high-pass filter?
I tried connecting it directly to gnd, +5V and analog pin to read output voltage; when untouched  the output is about 0; if I give it a little knock, the output momentarily goes to 2-3 V and then goes back to zero _very slow_, like, for a second or so. Why?

8  Using Arduino / Installation & Troubleshooting / Re: Arduino MEGA reboots with digital pin 5 set to high on: December 09, 2012, 11:10:05 pm
Solved. Initial assumption was correct - in case of intmittent and strange issues - this is a faulty hardware.
But that was really nasty one: I disconnected _everything from the button soldered on Adafruit datalogger board, pull-dopwn resistor, pin connection  - I only had Vcc on one pin and nothing at all on all other 3 pins - and it still effectively short-cut power when pushed.
I just removed the button and re-soldered it at different location, further away from the very edge -  and everything works now. My suggestion - Datalogger PCB micro-cracks, faulty middle-layer, or, it probably might be - some parasitic feedback effect.
9  Using Arduino / Installation & Troubleshooting / Re: Mega 2560 randomly hanging on: December 09, 2012, 12:11:34 pm
Interesting. What exactly 3 characters? Any link to more detailed info on this?
10  Using Arduino / Installation & Troubleshooting / Arduino MEGA reboots with digital pin 5 set to high on: December 09, 2012, 04:37:09 am
I am totally lost.
I placed  a button on digital 5, with pull-down resistor, when button pressed it gets +5v.
I also have somewhat complicated sketch which on first button press reads sensor data into attached QuadRAM board, then (on next button press) copies RAM into SD file; it also communicates some data (file name, storage progress etc) on serial LCD.
SD card is located on Adafruit datalogger board.
Libraries loaded are SD, I2cMaster.

Sometimes (without changing anything!) it stops working: when I press the button, the board just  reboots; moreover, it reboots with _power shortage_ (!!) - I can see it when LCD backlight blinks. If I just keep the button pressed, all LEDs are down.

When the board gets into that strange mode - it stays there even if I upload some other simple sketch, even with switching power off and on several times. Then, after a while (I still cannot figure after what actions) it gets to normal.

From  my experience when any device  behaves that strange, it is most probably hardware problem.

But still, - can anybody come up with at least a hint, what could it be (besides faulty board)?

I have  a feeling there is some "gray area" related to bootloader issues, when it switches to permanent reset loop or something. Can it be somehow related?

I do understand my description sounds very poor and messy and indeterminate. But so is the problem - it is intermittent and very unstable.



11  Using Arduino / Installation & Troubleshooting / Re: Mega 2560 randomly hanging on: December 09, 2012, 04:16:59 am
Obviously, uploading a sketch.
I also have multiple issues like that.
I have a feeling there is some 'gray area' somehow related to MEGA bootloader.
Sketch is complicated enough, with Adafruit datalogger shioeld, LCD shield and QuadRAM shield.
It might be working perfectly well for days, than something happens and you cannot upload anymore.
Sometimes uploading another  simple sketch helps, sometimes it does not.
My common impression is that Arduino MEGA 2560 is very unstable board, hardly useful for anything more complicated than blinking LEDs smiley-sad
BTW, Ard DUE is even  worse.


12  Using Arduino / Sensors / ADXL193: ST pin? on: December 03, 2012, 02:20:47 pm
I can't figure out from datasheet how I should connect ST pin?
I need no self-test, just for regular reading from OUT pin?
Should I ground ST or just leave it hanging?
13  Products / Arduino Due / Re: wrong readings from ADXL345 on: November 27, 2012, 10:13:36 am
well, since it is not 65535, 65535,65535 but -1,-1,-1 - this proves it is not 'int' format, this is something else. Might be bad contact somewhere, f.e. Try regular Arduino with the same sketch?
14  Products / Arduino Due / Re: wrong readings from ADXL345 on: November 26, 2012, 11:27:28 am
Hi,

how should I adjust the following code to run it on a due?

(ADXL 345 via SPI)

Code:
//Add the SPI library so we can communicate with the ADXL345 sensor
#include <SPI.h>

//Assign the Chip Select signal to pin 10.
int CS=10;

//This is a list of some of the registers available on the ADXL345.
//To learn more about these and the rest of the registers on the ADXL345, read the datasheet!
char POWER_CTL = 0x2D; //Power Control Register
char DATA_FORMAT = 0x31;
char DATAX0 = 0x32; //X-Axis Data 0
char DATAX1 = 0x33; //X-Axis Data 1
char DATAY0 = 0x34; //Y-Axis Data 0
char DATAY1 = 0x35; //Y-Axis Data 1
char DATAZ0 = 0x36; //Z-Axis Data 0
char DATAZ1 = 0x37; //Z-Axis Data 1

//This buffer will hold values read from the ADXL345 registers.
char values[10];
//These variables will be used to hold the x,y and z axis accelerometer values.
int x,y,z;

void setup(){
  //Initiate an SPI communication instance.
  SPI.begin();
  //Configure the SPI connection for the ADXL345.
  SPI.setDataMode(SPI_MODE3);
  //Create a serial connection to display the data on the terminal.
  Serial.begin(9600);
 
  //Set up the Chip Select pin to be an output from the Arduino.
  pinMode(CS, OUTPUT);
  //Before communication starts, the Chip Select pin needs to be set high.
  digitalWrite(CS, HIGH);
 
  //Put the ADXL345 into +/- 4G range by writing the value 0x01 to the DATA_FORMAT register.
  writeRegister(DATA_FORMAT, 0x01);
  //Put the ADXL345 into Measurement Mode by writing 0x08 to the POWER_CTL register.
  writeRegister(POWER_CTL, 0x08);  //Measurement mode 
}

void loop(){
  //Reading 6 bytes of data starting at register DATAX0 will retrieve the x,y and z acceleration values from the ADXL345.
  //The results of the read operation will get stored to the values[] buffer.
  readRegister(DATAX0, 6, values);

  //The ADXL345 gives 10-bit acceleration values, but they are stored as bytes (8-bits). To get the full value, two bytes must be combined for each axis.
  //The X value is stored in values[0] and values[1].
  x = ((int)values[1]<<8)|(int)values[0];
  //The Y value is stored in values[2] and values[3].
  y = ((int)values[3]<<8)|(int)values[2];
  //The Z value is stored in values[4] and values[5].
  z = ((int)values[5]<<8)|(int)values[4];
 
  //Print the results to the terminal.
  Serial.print(x, DEC);
  Serial.print(',');
  Serial.print(y, DEC);
  Serial.print(',');
  Serial.println(z, DEC);     
  delay(10);
}

//This function will write a value to a register on the ADXL345.
//Parameters:
//  char registerAddress - The register to write a value to
//  char value - The value to be written to the specified register.
void writeRegister(char registerAddress, char value){
  //Set Chip Select pin low to signal the beginning of an SPI packet.
  digitalWrite(CS, LOW);
  //Transfer the register address over SPI.
  SPI.transfer(registerAddress);
  //Transfer the desired register value over SPI.
  SPI.transfer(value);
  //Set the Chip Select pin high to signal the end of an SPI packet.
  digitalWrite(CS, HIGH);
}

//This function will read a certain number of registers starting from a specified address and store their values in a buffer.
//Parameters:
//  char registerAddress - The register addresse to start the read sequence from.
//  int numBytes - The number of registers that should be read.
//  char * values - A pointer to a buffer where the results of the operation should be stored.
void readRegister(char registerAddress, int numBytes, char * values){
  //Since we're performing a read operation, the most significant bit of the register address should be set.
  char address = 0x80 | registerAddress;
  //If we're doing a multi-byte read, bit 6 needs to be set as well.
  if(numBytes > 1)address = address | 0x40;
 
  //Set the Chip select pin low to start an SPI packet.
  digitalWrite(CS, LOW);
  //Transfer the starting register address that needs to be read.
  SPI.transfer(address);
  //Continue to read registers until we've read the number specified, storing the results to the input buffer.
  for(int i=0; i<numBytes; i++){
    values[i] = SPI.transfer(0x00);
  }
  //Set the Chips Select pin high to end the SPI packet.
  digitalWrite(CS, HIGH);
}

Code from: http://sparkfun.com/tutorial/ADXL/ADXL345_Basic.pde

I would just change
Code:
int x,y,z;
to
Code:
int16_t x,y,z;
15  Products / Arduino Due / Re: wrong readings from ADXL345 on: November 18, 2012, 12:17:51 pm
Hurray, we did it!
It works!
But I wonder, am I the only one who has noticed that?
Does not this mean that f.e ADXL345 library (and probably, many others?) must be corrected for DUE?
Pages: [1] 2 3 4