フィルターのクリア

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

2 ビュー (過去 30 日間)
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);
}
}
}

採用された回答

Walter Roberson
Walter Roberson 2016 年 1 月 29 日
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 件のコメント
Walter Roberson
Walter Roberson 2016 年 1 月 29 日
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 2016 年 1 月 30 日
編集済み: Cati Kati 2016 年 1 月 30 日
OMG, it works! thank you ever so much, I was dealing with it since 3 days. Thank you so muchh =)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by