Borrar filtros
Borrar filtros

Matlab - Arduino Communication. Matlab sends only 7bit data to arduino. How can i increase that?

2 visualizaciones (últimos 30 días)
Hi all, I want to send data from matlab to arduino. But, matlab sends only 7 bit data(between 0-127). How can increase that? I want to send 14 bit data(between 0-16384).
here is my arduino code
const int ledpin=13;
int recValue;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop()
{
if(Serial.available()>0)
{
recValue =Serial.read();
if (recValue == 12007) // If use will send value 100 from MATLAB then LED will turn ON
{
digitalWrite(ledpin, HIGH);
}
if(recValue == 10007) // If use will send value 101 from MATLAB then LED will turn OFF
{
digitalWrite(ledpin, LOW);
}
}
}

Respuesta aceptada

Walter Roberson
Walter Roberson el 29 de En. de 2016
On the MATLAB side, you will need to send multiple bytes, such as using fwrite(s,TheValue,'uint16') . On the Arduino side you will need to do two Serial.read() and construct recValue from that, such as by using
firstbyte<<8 | secondbyte
Be careful about the byte order: MATLAB is probably going to send the least significant byte first.
  3 comentarios
Walter Roberson
Walter Roberson el 29 de En. de 2016
The arduino gets 48-57 only if you used fprintf() with a numeric format such as %d or %f. If you use fwrite() then the byte values themselves would be sent.
If you do have the 48-57 range then subtract 48 to get the corresponding digit 0 to 9. You would probably need to put several of these digits together to build the decimal number. Binary (fwrite) is easier.
Cati Kati
Cati Kati el 30 de En. de 2016
Editada: Cati Kati el 30 de En. de 2016
OMG, it works! thank you ever so much, I was dealing with it since 3 days. Thank you so muchh =)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by