- Install the support for Arduino Hardware.
- Review the Arduino board library from the Simulink library browser and choose the required blocks for your model.
- Create a Simulink model for Arduino hardware.
- Configure and run the model on supported hardware.
how i read data from arduino in simulink real time?
37 views (last 30 days)
Show older comments
//Current
#include <Wire.h>
#include <Robojax_WCS.h>
#define MODEL 12 //see list above
#define SENSOR_PIN A0 //pin for reading sensor
#define SENSOR_VCC_PIN 8 //pin for powring up the sensor
#define ZERO_CURRENT_LED_PIN 2 //zero current LED pin
#define ZERO_CURRENT_WAIT_TIME 5000 //wait for 5 seconds to allow zero current measurement
#define CORRECTION_VLALUE 164 //mA
#define MEASUREMENT_ITERATION 100
#define VOLTAGE_REFERENCE 5000.0 //5000mv is for 5V
#define BIT_RESOLUTION 10
#define DEBUT_ONCE true
Robojax_WCS sensor(MODEL, SENSOR_PIN, SENSOR_VCC_PIN, ZERO_CURRENT_WAIT_TIME, ZERO_CURRENT_LED_PIN, CORRECTION_VLALUE,
MEASUREMENT_ITERATION, VOLTAGE_REFERENCE, BIT_RESOLUTION, DEBUT_ONCE);
//Motor Driver
int enA =7; //mendeklarasikan pin enA tehubung ke pin 3 arduino
int in_1 = 8;//mendeklarasikan pin in_1 tehubung ke pin 4 arduino
int in_2 = 9;//mendeklarasikan pin ein_2 tehubung ke pin 5 arduino
//Encoder
int PinEnCA=3 ;
int PinEnCB=4 ;
float rpm;
int pulse;
float deltaTime, now, lastTime;
int Gear=44.9, PPR=7;
char charValue[5];
String stringData;
void setup()
{
//Motor Driver
//Mendeklarasikan bahwa pin-pin tersebut bekerja sebagai OUTPUT
pinMode(enA,OUTPUT);
pinMode(in_1,OUTPUT);
pinMode(in_2,OUTPUT);
//Encoder
pinMode(PinEnCA,INPUT);
pinMode(PinEnCB,INPUT);
attachInterrupt(digitalPinToInterrupt(PinEnCA),callbackInterrupt, RISING);
//Current
Serial.begin(115200);
sensor.start();
Serial.print(sensor.getModel());
}
void loop()
{
gerak_1(); //memenaggil fungsi gerak 1
//RPM
now=millis();
deltaTime=now-lastTime;
if (deltaTime>=50){
rpm=(pulse*60.0*4000.0)/(Gear*PPR*deltaTime);
pulse=0;
lastTime=now;
}
Serial.print(rpm);
Serial.print (" ");
sensor.printCurrent();
delay(100);
}
void gerak_1(){
analogWrite(enA,255); //mengatur tegangan ke motor sebesar 20(0-255) dari tegangan input
//menentukan arah putar
digitalWrite(in_1,HIGH);
digitalWrite(in_2,LOW);
}
void callbackInterrupt(){
pulse++;
}
this is my code in arduino IDE, how can I read the "current" and "rpm" values in the simulink code in real time? by using the library in the code
0 Comments
Answers (1)
Srija Kethiri
on 18 Apr 2023
Hi Muhammad
I understand that you want to read the “current” and “rpm” values in the real time Simulink.
To read the values in Simulink, follow the below steps:
You can refer to the below video, to know more about Simulink IO on Arduino.:
To get started with the Arduino hardware in Simulink, refer to the following documentation:
Hope this helps!
0 Comments
See Also
Categories
Find more on Modeling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!