Matlab - Arduino Communication. Matlab sends only 7bit data to arduino. How can i increase that?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Cati Kati
le 29 Jan 2016
Modifié(e) : Cati Kati
le 30 Jan 2016
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);
}
}
}
0 commentaires
Réponse acceptée
Walter Roberson
le 29 Jan 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 commentaires
Walter Roberson
le 29 Jan 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!