chamakov 2 Posted April 16, 2013 Share Posted April 16, 2013 Hi everybody again, now i need all the comunity to help me... i need to read a single pin on my launchpad and plot those information in matlab, somebody can help me to do this?? i read in arduino playground a piece of code to call analogread() from matlab, with lauchpad its the same or what can i do to do this? Quote Link to post Share on other sites
mbeals 74 Posted April 16, 2013 Share Posted April 16, 2013 Do you have serial comm between the lauchpad and matlab yet? You need to set up the launchpad with a serial interrupt (there is an example of this included in energia). The basic code flow I would use would be something like: String command = ""; // a string to hold incoming data boolean processCommand = false; // whether the string is complete const int analogInPin = A0; void setup() { // initialize serial: Serial.begin(9600); // reserve 1 bytes for the inputString: inputString.reserve(1); } void loop() { // print the string when a newline arrives: if (processCommand) { int sensorValue = analogRead(analogInPin); Serial.println(sensorValue); processCommand = false; } } /* SerialEvent occurs whenever a new data comes in the hardware serial RX. This routine is run between each time loop() runs, so using delay inside loop can delay response. Multiple bytes of data may be available. */ void serialEvent() { while (Serial.available()) { // get the new byte: command = (char)Serial.read(); processCommand = true; } } No clue if that code will work or not, but it's a starting point. This is assuming that you are just transmitting an arbitrary bit to trigger the MCU to send back a reading. You could easily adapt it to actually record the byte transmitted and act on that value to send back something else (say the value on a different pin). The idea is to use an interrupt to wait for a byte to be sent to the UART. When that happens, it gets recorded and a "process me" flag is set. The main loop just loops waiting to see the "process me" flag...when that happens, it processes the command, sending the analog value back out on the UART. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.