bt hc06 pour envoyer message a la place de serial monitor

bonjour

au lieu d'utiliser le moniteur serie pour envoyer un message a la matrice de leds comment remplacer la liaison serie par le bluetooth, l'application android terminal serait "bluetooth spp".

le "croquis arduino" par moniteur serie

// Use the MD_MAX72XX library to scroll text on the display
//
// Demonstrates the use of the callback function to control what
// is scrolled on the display text.
//
// User can enter text on the serial monitor and this will display as a
// scrolling message on the display.
// Speed for the display is controlled by a pot on SPEED_IN analog in.

#include <MD_MAX72xx.h>

#define USE_POT_CONTROL 0
#define PRINT_CALLBACK 0

#define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); }

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define MAX_DEVICES 10

#define CLK_PIN 13 // or SCK
#define DATA_PIN 11 // or MOSI
#define CS_PIN 10 // or SS

// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(CS_PIN, MAX_DEVICES);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// Scrolling parameters
#if USE_POT_CONTROL
#define SPEED_IN A5
#else
#define SCROLL_DELAY 75 // in milliseconds
#endif // USE_POT_CONTROL

#define CHAR_SPACING 1 // pixels between characters

// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE 75
char curMessage[BUF_SIZE];
char newMessage[BUF_SIZE];
bool newMessageAvailable = false;

uint16_t scrollDelay; // in milliseconds

void readSerial(void)
{
static uint8_t putIndex = 0;

while (Serial.available())
{
newMessage[putIndex] = (char)Serial.read();
if ((newMessage[putIndex] == '\n') || (putIndex >= BUF_SIZE-3)) // end of message character or full buffer
{
// put in a message separator and end the string
newMessage[putIndex++] = ' ';
newMessage[putIndex] = '\0';
// restart the index for next filling spree and flag we have a message waiting
putIndex = 0;
newMessageAvailable = true;
}
else
// Just save the next char in next location
newMessage[putIndex++];
}
}

void scrollDataSink(uint8_t dev, MD_MAX72XX::transformType_t t, uint8_t col)
// Callback function for data that is being scrolled off the display
{
#if PRINT_CALLBACK
Serial.print("\n cb ");
Serial.print(dev);
Serial.print(' ');
Serial.print(t);
Serial.print(' ');
Serial.println(col);
#endif
}

uint8_t scrollDataSource(uint8_t dev, MD_MAX72XX::transformType_t t)
// Callback function for data that is required for scrolling into the display
{
static char *p = curMessage;
static uint8_t state = 0;
static uint8_t curLen, showLen;
static uint8_t cBuf[8];
uint8_t colData;

// finite state machine to control what we do on the callback
switch(state)
{
case 0: // Load the next character from the font table
showLen = mx.getChar(*p++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
curLen = 0;
state++;

// if we reached end of message, reset the message pointer
if (*p == '\0')
{
p = curMessage; // reset the pointer to start of message
if (newMessageAvailable) // there is a new message waiting
{
strcpy(curMessage, newMessage); // copy it in
newMessageAvailable = false;
}
}
// !! deliberately fall through to next state to start displaying

case 1: // display the next part of the character
colData = cBuf[curLen++];
if (curLen == showLen)
{
showLen = CHAR_SPACING;
curLen = 0;
state = 2;
}
break;

case 2: // display inter-character spacing (blank column)
colData = 0;
curLen++;
if (curLen == showLen)
state = 0;
break;

default:
state = 0;
}

return(colData);
}

void scrollText(void)
{
static uint32_t prevTime = 0;

// Is it time to scroll the text?
if (millis()-prevTime >= scrollDelay)
{
mx.transform(MD_MAX72XX::TSL); // scroll along - the callback will load all the data
prevTime = millis(); // starting point for next time
}
}

uint16_t getScrollDelay(void)
{
#if USE_POT_CONTROL
uint16_t t;

t = analogRead(SPEED_IN);
t = map(t, 0, 1023, 25, 250);

return(t);
#else
return(SCROLL_DELAY);
#endif
}

void setup()
{
mx.begin();
mx.setShiftDataInCallback(scrollDataSource);
mx.setShiftDataOutCallback(scrollDataSink);

#if USE_POT_CONTROL
pinMode(SPEED_IN, INPUT);
#else
scrollDelay = SCROLL_DELAY;
#endif

strcpy(curMessage, "- - - - - - ");
newMessage[0] = '\0';

Serial.begin(57600);
Serial.print("\n[MD_MAX72XX Message Display]\nType a message for the scrolling display\nEnd message line with a newline");
}

void loop()
{
scrollDelay = getScrollDelay();
readSerial();
scrollText();
}

j'ouvre le moniteur serie 57600 bauds, j'ecris le nouveau message à afficher, envoyer

au lieu de passer par pc+moniteur serie, j'aimerais le faire par bluetooth et phone android

que faut-il modifier dans le croquis précédent ?

merci et meilleurs voeux de bonheur pour 2016

bonjour
merci pour tes voeux
il faut dabord lire ceci

pour y trouver la façon de mettre du code entre balises

merci

et ce n'est pas "envoyer" mais recevoir le message avec hc06, message qui sera envoyé par le phone android en bluetooth

// Use the MD_MAX72XX library to scroll text on the display
//
// Demonstrates the use of the callback function to control what
// is scrolled on the display text.
//
// User can enter text on the serial monitor and this will display as a
// scrolling message on the display.
// Speed for the display is controlled by a pot on SPEED_IN analog in.

#include <MD_MAX72xx.h>

#define   USE_POT_CONTROL   0
#define   PRINT_CALLBACK   0

#define   PRINT(s, v)   { Serial.print(F(s)); Serial.print(v); }

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define   MAX_DEVICES   10

#define   CLK_PIN      13  // or SCK
#define   DATA_PIN   11  // or MOSI
#define   CS_PIN      10  // or SS

// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(CS_PIN, MAX_DEVICES);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// Scrolling parameters
#if USE_POT_CONTROL
#define   SPEED_IN   A5
#else
#define SCROLL_DELAY   75   // in milliseconds
#endif // USE_POT_CONTROL

#define   CHAR_SPACING   1   // pixels between characters

// Global message buffers shared by Serial and Scrolling functions
#define   BUF_SIZE   75
char curMessage[BUF_SIZE];
char newMessage[BUF_SIZE];
bool newMessageAvailable = false;

uint16_t   scrollDelay;   // in milliseconds

void readSerial(void)
{
  static uint8_t   putIndex = 0;

  while (Serial.available())
  {
    newMessage[putIndex] = (char)Serial.read();
    if ((newMessage[putIndex] == '\n') || (putIndex >= BUF_SIZE-3))   // end of message character or full buffer
    {
      // put in a message separator and end the string
      newMessage[putIndex++] = ' ';
      newMessage[putIndex] = '\0';
      // restart the index for next filling spree and flag we have a message waiting
      putIndex = 0;
      newMessageAvailable = true;
    }
    else
      // Just save the next char in next location
      newMessage[putIndex++];
  }
}

void scrollDataSink(uint8_t dev, MD_MAX72XX::transformType_t t, uint8_t col)
// Callback function for data that is being scrolled off the display
{
#if PRINT_CALLBACK
  Serial.print("\n cb ");
  Serial.print(dev);
  Serial.print(' ');
  Serial.print(t);
  Serial.print(' ');
  Serial.println(col);
#endif
}

uint8_t scrollDataSource(uint8_t dev, MD_MAX72XX::transformType_t t)
// Callback function for data that is required for scrolling into the display
{
  static char      *p = curMessage;
  static uint8_t   state = 0;
  static uint8_t   curLen, showLen;
  static uint8_t   cBuf[8];
  uint8_t colData;

  // finite state machine to control what we do on the callback
  switch(state)
  {
    case 0:   // Load the next character from the font table
      showLen = mx.getChar(*p++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
      curLen = 0;
      state++;

      // if we reached end of message, reset the message pointer
      if (*p == '\0')
      {
        p = curMessage;         // reset the pointer to start of message
        if (newMessageAvailable)   // there is a new message waiting
        {
          strcpy(curMessage, newMessage);   // copy it in
          newMessageAvailable = false;
        }
      }
      // !! deliberately fall through to next state to start displaying

    case 1:   // display the next part of the character
      colData = cBuf[curLen++];
      if (curLen == showLen)
      {
        showLen = CHAR_SPACING;
        curLen = 0;
        state = 2;
      }
      break;

    case 2:   // display inter-character spacing (blank column)
      colData = 0;
      curLen++;
      if (curLen == showLen)
        state = 0;
      break;

    default:
      state = 0;
  }

  return(colData);
}

 void scrollText(void)
{
  static uint32_t   prevTime = 0;

  // Is it time to scroll the text?
  if (millis()-prevTime >= scrollDelay)
  {
    mx.transform(MD_MAX72XX::TSL);   // scroll along - the callback will load all the data
    prevTime = millis();         // starting point for next time
  }
}

uint16_t getScrollDelay(void)
{
#if USE_POT_CONTROL
  uint16_t   t;

  t = analogRead(SPEED_IN);
  t = map(t, 0, 1023, 25, 250);

  return(t);
#else
  return(SCROLL_DELAY);
#endif
}

void setup()
{
  mx.begin();
  mx.setShiftDataInCallback(scrollDataSource);
  mx.setShiftDataOutCallback(scrollDataSink);

#if USE_POT_CONTROL
  pinMode(SPEED_IN, INPUT);
#else
  scrollDelay = SCROLL_DELAY;
#endif

  strcpy(curMessage, "-  -  -  -   -   -             ");
  newMessage[0] = '\0';

  Serial.begin(57600);
  Serial.print("\n[MD_MAX72XX Message Display]\nType a message for the scrolling display\nEnd message line with a newline");
}

void loop()
{
  scrollDelay = getScrollDelay();
  readSerial();
  scrollText();
}

elektrax:
merci

et ce n'est pas "envoyer" mais recevoir le message avec hc06, message qui sera envoyé par le phone android en bluetooth

bonjour
Il faut voir le HC06 au niveau de ses pins comme une simple terminaison UART RX/TX
une fois appairé et utilisé avec un soft , c'est parfaitement transparent.
perso sur android j'utilise Amarino avec sa fonction monitoring pour faire de la comm serial basique

merci

j'ai adapté plus ou moins un sketch, çà fonctionne de maniere basique, il y a surement moyen de faire beaucoup mieux et il ne reconnait pas les caracteres accentués

// Use the Parola library to scroll text on the display
//
// Demonstrates the use of the scrolling function to display text received 
// from [s]the serial interface[/s] : par bluetooth !!!
//
// User can enter text on the [s]serial monitor[/s] and this will display as a
// scrolling message on the display.
// Speed for the display is controlled by a pot on SPEED_IN analog in.
// Scrolling direction is controlled by a switch on DIRECTION_SET digital in.
// Invert ON/OFF is set by a switch on INVERT_SET digital in.
//
// Keyswitch library can be found at http://arduinocode.codeplex.com
//
// defilement de gauche à droite, le message est envoyé par appli android
// bluetooth spp pro le hc06 a ete configuré en 57600 baud

#include <MD_Parola.h>
#include <MD_MAX72xx.h> // ATTENTION suivant le modele des matrices il faut choisir
// le modele dans le fichier md max72xx.h, ici ce sont des hc-16
#include <SoftwareSerial.h> //pour mettre hc06 sur pins autres que 0 et 1

SoftwareSerial BT(8, 9);   //pin 8 : virtual RX    pin 9 :  virtual TX
// le tx d'arduino relié au rx du hc06 doit passer par un diviseur a resistances ou un shiftlevel 5v>3v

// set to 1 if we are implementing the user interface pot, switch, etc
#define	USE_UI_CONTROL	0  // pas utilisé ici
// le nec le plus ultra serait de pouvoir controler a partir d'android
//c'est hors du champ de mes connaissances

#if USE_UI_CONTROL
#include <MD_KeySwitch.h>
#endif

// Turn on debug statements to the serial output
#define  DEBUG  1

#if  DEBUG
#define	PRINT(s, x)	{ Serial.print(F(s)); Serial.print(x); }
#define	PRINTS(x)	Serial.print(F(x))
#define	PRINTX(x)	Serial.println(x, HEX)
#else
#define	PRINT(s, x)
#define PRINTS(x)
#define PRINTX(x)
#endif

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may 
// need to be adapted
#define	MAX_DEVICES	10
#define	CLK_PIN		13
#define	DATA_PIN	11
#define	CS_PIN		10

// HARDWARE SPI
MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES);
// SOFTWARE SPI
//MD_Parola P = MD_Parola(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);


#define	PAUSE_TIME		1000
#define	SPEED_DEADBAND	5

// Scrolling parameters
#if USE_UI_CONTROL
#define	SPEED_IN		A5
#define	DIRECTION_SET	8	// change the effect
#define	INVERT_SET		9	// change the invert

#endif // USE_UI_CONTROL

uint8_t	frameDelay = 25;	// default frame delay value
textEffect_t	scrollEffect = SCROLL_LEFT;

// Global message buffers shared by Serial and Scrolling functions
#define	BUF_SIZE	75
char curMessage[BUF_SIZE];
char newMessage[BUF_SIZE];
bool newMessageAvailable = false;

#if USE_UI_CONTROL

MD_KeySwitch uiDirection(DIRECTION_SET);
MD_KeySwitch uiInvert(INVERT_SET);

void doUI(void)
{
  // set the speed if it has changed
  {
    int16_t	speed = map(analogRead(SPEED_IN), 0, 1023, 10, 150);

    if ((speed >= ((int16_t)P.getSpeed() + SPEED_DEADBAND)) || 
      (speed <= ((int16_t)P.getSpeed() - SPEED_DEADBAND)))
    {
      P.setSpeed(speed);
      P.setPause(speed);
      frameDelay = speed;
      PRINT("\nChanged speed to ", P.getSpeed());
    }
  }

  if (uiDirection.read() == MD_KeySwitch::KS_PRESS)	// SCROLL DIRECTION
  {
    PRINTS("\nChanging scroll direction");
    scrollEffect = (scrollEffect == SCROLL_LEFT ? SCROLL_RIGHT : SCROLL_LEFT);
    P.setTextEffect(scrollEffect, scrollEffect);
    P.displayReset();
  }

  if (uiInvert.read() == MD_KeySwitch::KS_PRESS)	// INVERT MODE
  {
    PRINTS("\nChanging invert mode");
    P.setInvert(!P.getInvert());
  }
}
#endif // USE_UI_CONTROL

void readSerial(void)
{
  static uint8_t	putIndex = 0;

  while (BT.available())
  {
    newMessage[putIndex] = (char)BT.read();
    if ((newMessage[putIndex] == '\n') || (putIndex >= BUF_SIZE-2))	// end of message character or full buffer
    {
      // put in a message separator and end the string
      newMessage[putIndex] = '\0';
      // restart the index for next filling spree and flag we have a message waiting
      putIndex = 0;
      newMessageAvailable = true;
    }
      else
      // Just save the next char in next location
      newMessage[putIndex++];
  }
}

void setup()
{
  BT.begin(57600);

#if USE_UI_CONTROL
  uiDirection.begin();
  uiInvert.begin();
  pinMode(SPEED_IN, INPUT);

  doUI();
#endif // USE_UI_CONTROL

  P.begin();
  P.displayClear();
  P.displaySuspend(false);

  P.displayScroll(curMessage, LEFT, scrollEffect, frameDelay);

  strcpy(curMessage, "Hello! Enter new message?");
  newMessage[0] = '\0';

  BT.begin(57600);
  BT.print("\n[Parola Scrolling Display]\nType a message for the scrolling display\nEnd message line with a newline");
}

void loop() 
{
#if USE_UI_CONTROL
	doUI();
#endif // USE_UI_CONTROL

  readSerial();
  if (P.displayAnimate()) 
  {
    if (newMessageAvailable)
    {
      strcpy(curMessage, newMessage);
      newMessageAvailable = false;
    }
    P.displayReset();
  }
}