๐ŸŽ„โ›„โ„๏ธ๐ŸŽ It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! ๐ŸŽ„โ›„โ„๏ธ๐ŸŽ
0

Temp Read out in Scrolling Text Help
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Temp Read out in Scrolling Text Help

by jlh127 on Wed Apr 13, 2016 5:12 pm

Hi there! I'm very new to arduino as well as to LED Matrix. I'm a student at the University of West Florida. For my Interactive Design final, I am building a thermometer on an LED matrix using the 16 x 32 matrix I bought from adafruit as well as the temp sensors.

Alright, so, here's what I have. I have my LED matrix completely wired to an arduino Uno. I also have the temp sensor wired in as well. I've run both sets of code and both work. I was then able to combine two codes into one and they both still work.

The codes I have include the RGB Matrix library from adafruit and then a temp code I found as well as a processor code to display the temp in a graph.

I've gone over this with my teacher and we were trying to figure out how to get the scrolling text to display the temperature readout from tempC.

We've gotten it down to:

const char str[] PROGMEM = "Adafruit 16x32 RGB LED Matrix";


..as this is what shows the text in the animation. I've researched progMem but I'm not understanding it. He said somehow we need to get progMem to read out tempC..but whenever I change any of that code I get errors. I'm still doing research, but I'm still very much confused about this. Is there another code I need to add in?

To summarize, I need the scrolling text to read the temperature data from tempC .

Also if this is the wrong place to post this, please let me know where to move this too.

jlh127
 
Posts: 5
Joined: Wed Apr 13, 2016 5:05 pm

Re: Temp Read out in Scrolling Text Help

by adafruit_support_rick on Thu Apr 14, 2016 11:25 am

The Arduino Uno uses a chip from the AVR family. The AVR has what is known as a "Harvard Architecture". That means that the program and data are in separate address spaces. PROGMEM refers to the program address space. You can store data in program space, but it will be static, not variable. The PROGMEM directive tells the compiler to store a block of data in program space.

When your program is running, there are functions which allow you to move data from program space to data space, but you can't go the other way. Your program can't move variables from data space to program space

So, you can't put your temperature data in PROGMEM.

In the scrolltext example, you will see that it uses the F2 macro. This macro copies the string from PROGMEM to data space so that it can be displayed on the matrix.
Code: Select all | TOGGLE FULL SIZE
  matrix.print(F2(str));


You will construct your temperature string in data space, so you don't want to use the F2 macro.

Question: Will your temperature data be a floating-point data type? You have to handle floating point data in a special way to include it in a string.

I can give you some code to construct the string either way.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Temp Read out in Scrolling Text Help

by jlh127 on Mon Apr 18, 2016 1:36 pm

Sorry it took me so long to get back with you - I've been sick with the flu since Thursday and haven't been able to concentrate much. I'm back in class today and wanted to go ahead and post the code I currently have. It'll have the combined code of the temperature and the scroll text.



Code: Select all | TOGGLE FULL SIZE
// scrolltext demo for Adafruit RGBmatrixPanel library.
// Demonstrates double-buffered animation on our 16x32 RGB LED matrix:
// http://www.adafruit.com/products/420

// Written by Limor Fried/Ladyada & Phil Burgess/PaintYourDragon
// for Adafruit Industries.
// BSD license, all text above must be included in any redistribution.

float tempC;
int tempPin = 5;



#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library

// Similar to F(), but for PROGMEM string pointers rather than literals
#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr

#define CLK 8  // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2
// Last parameter = 'true' enables double-buffering, for flicker-free,
// buttery smooth animation.  Note that NOTHING WILL SHOW ON THE DISPLAY
// until the first call to swapBuffers().  This is normal.
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
// Double-buffered mode consumes nearly all the RAM available on the
// Arduino Uno -- only a handful of free bytes remain.  Even the
// following string needs to go in PROGMEM:

const char str[] PROGMEM = "Adafruit 16x32 RGB LED Matrix";
int    textX   = matrix.width(),
       textMin = sizeof(str) * -12,
       hue     = 0;
int8_t ball[3][4] = {
  {  3,  0,  1,  1 }, // Initial X,Y pos & velocity for 3 bouncy balls
  { 17, 15,  1, -1 },
  { 27,  4, -1,  1 }
};
static const uint16_t PROGMEM ballcolor[3] = {
  0x0080, // Green=1
  0x0002, // Blue=1
  0x1000  // Red=1
};

  void setup() {
 matrix.begin();
  matrix.setTextWrap(false); // Allow text to run off right edge
  matrix.setTextSize(2);




  Serial.begin(9600); //opens serial port, sets data rate to 9600 bps

 
}

void loop() {
  byte i;

tempC = analogRead(tempPin);           //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
Serial.print((byte)tempC);             //send the data to the computer
//delay(1000);

  // Clear background
  matrix.fillScreen(0);

  // Bounce three balls around
  for(i=0; i<3; i++) {
    // Draw 'ball'
    matrix.fillCircle(ball[i][0], ball[i][1], 5, pgm_read_word(&ballcolor[i]));
    // Update X, Y position
    ball[i][0] += ball[i][2];
    ball[i][1] += ball[i][3];
    // Bounce off edges
    if((ball[i][0] == 0) || (ball[i][0] == (matrix.width() - 1)))
      ball[i][2] *= -1;
    if((ball[i][1] == 0) || (ball[i][1] == (matrix.height() - 1)))
      ball[i][3] *= -1;
  }

  // Draw big scrolly text on top
  matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
 matrix.setCursor(textX, 1);
 matrix.print(F2(str));





  // Move text left (w/wrap), increase hue
  if((--textX) < textMin) textX = matrix.width();
  hue += 7;
  if(hue >= 1536) hue -= 1536;

  // Update display
  matrix.swapBuffers(false);
}

jlh127
 
Posts: 5
Joined: Wed Apr 13, 2016 5:05 pm

Re: Temp Read out in Scrolling Text Help

by adafruit_support_rick on Tue Apr 19, 2016 10:18 am

So, I presume you don't want the bouncing balls.

What you do is to replace the PROGMEM string with a regular variable char buffer. You'll also need a smaller buffer to convert the temperature from float to a string.

Use the dtostrf function to convert the float to a string, then use the snprintf function to build your scrolling string:
Code: Select all | TOGGLE FULL SIZE
// scrolltext demo for Adafruit RGBmatrixPanel library.
// Demonstrates double-buffered animation on our 16x32 RGB LED matrix:
// http://www.adafruit.com/products/420

// Written by Limor Fried/Ladyada & Phil Burgess/PaintYourDragon
// for Adafruit Industries.
// BSD license, all text above must be included in any redistribution.

float tempC;
int tempPin = 5;



#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library


#define CLK 8  // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2
// Last parameter = 'true' enables double-buffering, for flicker-free,
// buttery smooth animation.  Note that NOTHING WILL SHOW ON THE DISPLAY
// until the first call to swapBuffers().  This is normal.
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
// Double-buffered mode consumes nearly all the RAM available on the
// Arduino Uno -- only a handful of free bytes remain.  Even the
// following string needs to go in PROGMEM:

#define STRING_SIZE 32

char str[STRING_SIZE];  //the string to scroll
char tempBuffer[8];     //storage for the temperature substring

int    textX   = matrix.width(),
       textMin = sizeof(str) * -12,
       hue     = 0;


void setup() {
  matrix.begin();
  matrix.setTextWrap(false); // Allow text to run off right edge
  matrix.setTextSize(2);

  Serial.begin(9600); //opens serial port, sets data rate to 9600 bps

}

void loop() {
  byte i;

  tempC = analogRead(tempPin);           //read the value from the sensor
  tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
  Serial.print(tempC);                  //send the data to the computer

  snprintf(str, STRING_SIZE-1, "Current Temperature is %s", dtostrf(tempC, 6, 2, tempBuffer));

  // Clear background
  matrix.fillScreen(0);

  matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
  matrix.setCursor(textX, 1);
  matrix.print(str);

  // Move text left (w/wrap), increase hue
  if((--textX) < textMin) textX = matrix.width();
  hue += 7;
  if(hue >= 1536) hue -= 1536;

  // Update display
  matrix.swapBuffers(false);
}

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Temp Read out in Scrolling Text Help

by jlh127 on Wed Apr 20, 2016 2:28 pm

Okay, so I followed along and saw what you meant. However, when I uploaded the code (it all checked out), the display to my LED matrix will not turn on. THe arduino is on and the LED matrix worked (as it loaded the previous test code I had in it prior to uploading the new one.) Suggestions?

jlh127
 
Posts: 5
Joined: Wed Apr 13, 2016 5:05 pm

Re: Temp Read out in Scrolling Text Help

by jlh127 on Wed Apr 20, 2016 4:46 pm

Okay, so we went back and worked with it a bit (my teacher and I). We found out that there is some sort of conflict with the temperature sensor and the code. When we run the program the lights on the matrix will flash and then it'll turn off. When we check the temperature through arduino, it'll read the temperature twice but then stop. My professor says it seems like there is a conflict where the program is getting stuck. He and I are both stumped. I posted the code again with the few edits made.


Edit: We also double checked by running my original code to make sure that the temp sensor is working and reading - and it was reading fine for it. It is only when we try the new code with the strings where it starts acting up.


Code: Select all | TOGGLE FULL SIZE
// scrolltext demo for Adafruit RGBmatrixPanel library.
// Demonstrates double-buffered animation on our 16x32 RGB LED matrix:
// http://www.adafruit.com/products/420

// Written by Limor Fried/Ladyada & Phil Burgess/PaintYourDragon
// for Adafruit Industries.
// BSD license, all text above must be included in any redistribution.

float tempC;
int tempPin = A5;



#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library


#define CLK 8  // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2
// Last parameter = 'true' enables double-buffering, for flicker-free,
// buttery smooth animation.  Note that NOTHING WILL SHOW ON THE DISPLAY
// until the first call to swapBuffers().  This is normal.
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
// Double-buffered mode consumes nearly all the RAM available on the
// Arduino Uno -- only a handful of free bytes remain.  Even the
// following string needs to go in PROGMEM:

#define STRING_SIZE 32

char str[STRING_SIZE];  //the string to scroll
char tempBuffer[8];     //storage for the temperature substring

int    textX   = matrix.width(),
       textMin = sizeof(str) * -12,
       hue     = 0;


void setup() {
  matrix.begin();
  matrix.setTextWrap(false); // Allow text to run off right edge
  matrix.setTextSize(2);

  //Serial.begin(9600); //opens serial port, sets data rate to 9600 bps

}

void loop() {
  byte i;

  tempC = analogRead(tempPin);           //read the value from the sensor
  tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
  //Serial.println(tempC);//send the data to the computer
  delay(1000);
 
  snprintf(str, STRING_SIZE-1, "Current Temperature is %s", dtostrf(tempC, 6, 2, tempBuffer));

  // Clear background
  matrix.fillScreen(0);

  matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
  matrix.setCursor(textX, 1);
  matrix.print(str);

  // Move text left (w/wrap), increase hue
  if((--textX) < textMin) textX = matrix.width();
  hue += 7;
  if(hue >= 1536) hue -= 1536;

  // Update display
  matrix.swapBuffers(false);
}



adafruit_support_rick wrote:So, I presume you don't want the bouncing balls.

What you do is to replace the PROGMEM string with a regular variable char buffer. You'll also need a smaller buffer to convert the temperature from float to a string.

Use the dtostrf function to convert the float to a string, then use the snprintf function to build your scrolling string:
Code: Select all | TOGGLE FULL SIZE
// scrolltext demo for Adafruit RGBmatrixPanel library.
// Demonstrates double-buffered animation on our 16x32 RGB LED matrix:
// http://www.adafruit.com/products/420

// Written by Limor Fried/Ladyada & Phil Burgess/PaintYourDragon
// for Adafruit Industries.
// BSD license, all text above must be included in any redistribution.

float tempC;
int tempPin = 5;



#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library


#define CLK 8  // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2
// Last parameter = 'true' enables double-buffering, for flicker-free,
// buttery smooth animation.  Note that NOTHING WILL SHOW ON THE DISPLAY
// until the first call to swapBuffers().  This is normal.
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
// Double-buffered mode consumes nearly all the RAM available on the
// Arduino Uno -- only a handful of free bytes remain.  Even the
// following string needs to go in PROGMEM:

#define STRING_SIZE 32

char str[STRING_SIZE];  //the string to scroll
char tempBuffer[8];     //storage for the temperature substring

int    textX   = matrix.width(),
       textMin = sizeof(str) * -12,
       hue     = 0;


void setup() {
  matrix.begin();
  matrix.setTextWrap(false); // Allow text to run off right edge
  matrix.setTextSize(2);

  Serial.begin(9600); //opens serial port, sets data rate to 9600 bps

}

void loop() {
  byte i;

  tempC = analogRead(tempPin);           //read the value from the sensor
  tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
  Serial.print(tempC);                  //send the data to the computer

  snprintf(str, STRING_SIZE-1, "Current Temperature is %s", dtostrf(tempC, 6, 2, tempBuffer));

  // Clear background
  matrix.fillScreen(0);

  matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
  matrix.setCursor(textX, 1);
  matrix.print(str);

  // Move text left (w/wrap), increase hue
  if((--textX) < textMin) textX = matrix.width();
  hue += 7;
  if(hue >= 1536) hue -= 1536;

  // Update display
  matrix.swapBuffers(false);
}

jlh127
 
Posts: 5
Joined: Wed Apr 13, 2016 5:05 pm

Re: Temp Read out in Scrolling Text Help

by adafruit_support_rick on Thu Apr 21, 2016 11:08 am

Hmmm. Try turning off double-buffer mode:
Code: Select all | TOGGLE FULL SIZE
// Last parameter = 'true' enables double-buffering, for flicker-free,
// buttery smooth animation.  Note that NOTHING WILL SHOW ON THE DISPLAY
// until the first call to swapBuffers().  This is normal.
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
// Double-buffered mode consumes nearly all the RAM available on the
// Arduino Uno -- only a handful of free bytes remain.  Even the
// following string needs to go in PROGMEM:


adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Temp Read out in Scrolling Text Help

by jlh127 on Thu Apr 21, 2016 5:15 pm

Okay, I did that. I'm getting more readings but the screen still isn't turning on. I'm trying a few things still...

Edit: Not entirely sure what I did, but I got it to come on! Okay, so, the temperature is reading way too fast. I've gotten the text to slow down but where do I add the delay for the temperature readings?


adafruit_support_rick wrote:Hmmm. Try turning off double-buffer mode:
Code: Select all | TOGGLE FULL SIZE
// Last parameter = 'true' enables double-buffering, for flicker-free,
// buttery smooth animation.  Note that NOTHING WILL SHOW ON THE DISPLAY
// until the first call to swapBuffers().  This is normal.
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
// Double-buffered mode consumes nearly all the RAM available on the
// Arduino Uno -- only a handful of free bytes remain.  Even the
// following string needs to go in PROGMEM:


jlh127
 
Posts: 5
Joined: Wed Apr 13, 2016 5:05 pm

Re: Temp Read out in Scrolling Text Help

by adafruit_support_rick on Thu Apr 21, 2016 5:51 pm

This should read the temperature once every second (1000ms)
Code: Select all | TOGGLE FULL SIZE
uint32_t  temptimer = millis();
void loop() {
  byte i;

  if ((millis() - temptimer) > 1000)
  {
    temptimer = millis();
    tempC = analogRead(tempPin);           //read the value from the sensor
    tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
    Serial.print(tempC);                  //send the data to the computer
 
    snprintf(str, STRING_SIZE-1, "Current Temperature is %s", dtostrf(tempC, 6, 2, tempBuffer));

  }
  // Clear background
  matrix.fillScreen(0);

  matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
  matrix.setCursor(textX, 1);
  matrix.print(str);

  // Move text left (w/wrap), increase hue
  if((--textX) < textMin) textX = matrix.width();
  hue += 7;
  if(hue >= 1536) hue -= 1536;

  // Update display
  matrix.swapBuffers(false);
}

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Please be positive and constructive with your questions and comments.