Newbie Arduino Serial to Dot Matrix

Hi

Does anyone know if it is possible to take the value of the accelerometer which is available in the serial monitor and send this to a dot matrix panel?. This is the code I am using for the accelerometer to text box.

#include <Arduino.h>
#include <ADXL335.h>

const int xpin = A0; // x-axis of the accelerometer
const int ypin = A1; // y-axis
const int zpin = A2; // z-axis

void setup()

{

Serial.begin(9600);

}

void loop()

{

float zero_G = 512.0; //ADC is 0~1023 the zero g output equal to Vs/2
float scale = 102.4; //ADXL335330 Sensitivity is 330mv/g
float accel_y = ((y - 329.5) / 68.5 * 9.8);

Serial.print(accel_y);
Serial.println("%");

dtostrf(accel_y, 0, 2, text_1);

delay(2000);

}

Thanks Andy

You have made 30 posts already and you do not know how to post code?

Thanks Paul_B

Tried posting my code correctly and still cant get it to work, but at least you tried to help me :slight_smile:

You should edit your message and place CODE tags around your code. Also for more ease of read, use CTRL T when in the IDE to indent it properly. It will look like that :

#include <Arduino.h>
#include <ADXL335.h>

const int xpin = A0; // x-axis of the accelerometer

and so on…

These lines of your code are not correct :

float accel_y = ((y - 329.5) / 68.5 * 9.8);

...

dtostrf(accel_y, 0, 2, text_1);

The variable y is not defined. I guess it is the reading from pin A1. You should add before :

int y = analogRead(ypin);

The use of dtostrf is also incorrect.

Function dtostrf()
char * dtostrf(
double __val,
signed char __width,
unsigned char __prec,
char * __s)
The dtostrf() function converts the double value passed in val into an ASCII representation that will be stored under s. The caller is responsible for providing sufficient storage in s.

Conversion is done in the format “[-]d.ddd”. The minimum field width of the output string (including the possible ‘.’ and the possible sign for negative values) is given in width, and prec determines the number of digits after the decimal sign. width is signed value, negative for left adjustment.

The dtostrf() function returns the pointer to the converted string s.

The second argument, width, can not be 0. If accel_y is a percentage and possibly negative, then the max format would be -xxx.xx if you want 2 figures after the dot. So the width is no less than 7.

So you need to declare the char array text_1 and write into it:

char text_1[8];
dtostrf(accel_y, 7, 2, text_1);

Hi lesept

Thank you for your reply and help, I will endevour to post my code correctly next time. Do you know if it is possible to send the serial read out to a dot matrix screen?

Thanks
Andy

Look for MAX7219 Serial displays. That may be the sort of thing you want.

Steve

Make sure that the dtostr() call is working correctly by printing the result after the function call.

Once you have the data in a string (character array, nul terminated) you can use the MD_Parola libraries (for text special effects) or just the MD_MAX72xx library (straight display) to display the information on a led matrix display.

The libraries have lots of example code to follow and are extensively documented.

Find the libraries in my code repository, link in the signature block.

Hi Marco

Thank you for the reply, I am awaiting my screen but will try as soon as I get it. I know I can print the accelerometer reading to the serial print so that it not a problem. I then only need to send it to the dot matrix screen. Does your libraries work with other screens?

Many Thanks
Andy

andyturner:
I will endeavour to post my code correctly next time.

No, not next time, now. Go back and edit you first post - “More”->“Modify” option at the bottom right of the post, highlight the code section, click the “code” option (</>). Did you not notice some strange things in there?

Steady on now boy, let’s not make a drama out of a crisis

And let's not bother answering questions from people who can't be bothered to ask them properly. Works for me.

Steve

Great what code did you use?

Displays are made up of individual MAX7219 controlled 8x8 LED modules strung together. The documentation for MD_MAX72xx library has pictures and explanation of of what is supported.

Hi Marco

Does your libraries work with the Adafruit led matrix?

Many Thanks
Andy

If the Adafruit matrix is controlled by the MD_MAX72xx it will. I have no idea what they use as the hardware controller but you could find out easily enough.

andyturner:
Steady on now boy, let’s not make a drama out of a crisis

If you can’t be arsed following the rules many people here think you don’t deserve help.

If you are too stupid to understand the rules then the odds that you are not smart enough to understand any answers you get here.