Teensy 3.1 + Matlab/Simulink

Status
Not open for further replies.

hl68fx

New member
Hi,

I have connected an analog sensor to my teensy 3.1. Now I would like to aquire the values (for example every half second) in Matlab or Simulink. Is there a way to generate this code in Simulink? Or do I have to use a serial conntection in Matlab? Is there any sample code available? Thank you very much for your help in advance!

Kind regards,
Thomas
 
something like this will work -- Matlab will need to be configured to read from a serial port:

{I haven't tried this; could be buggy !}

Code:
#define LEDPIN 13
#define ANALOGPIN A0 // Pin 14 on Teensy 3.0

void setup() {                
  Serial.begin(9600);
  pinMode(LEDPIN, OUTPUT);
}

int AnalogValue;

void loop() {
  AnalogValue = analogRead(ANALOGPIN);
  digitalWrite(LEDPIN, HIGH); // pulse LED 
  Serial.print("Read Value of:"); Serial.println(AnalogValue);
  delay(100);
  digitalWrite(LEDPIN, LOW); 
  delay(400); // not perfect 500 ms total because of time consumed by above lines.
}
 
Status
Not open for further replies.
Back
Top