필터 지우기
필터 지우기

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 CenterFile Exchange에서 MATLAB 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