• Hello,
    How do I go about reading Serial data coming from a PC via USB and write that to the SD card?
    I've tried the code below but nothing gets written to data.txt and LED2 doesn't flash.

        function onInit() {
        digitalWrite(LED2,1);
        var cmd="";
        var fs = require("fs");
    
        Serial1.setup(9600/*baud*/);
        Serial1.on('data', function () { 
          digitalWrite(LED2,0);
      
          cmd+=data;
          var idx = cmd.indexOf("\r");
    
          while (idx>=0) {
            var line = cmd.substr(0,idx);
            cmd = cmd.substr(idx+1);
            var s = "'"+line+"' = "+eval(line); 
            idx = cmd.indexOf("\r");
        
            fs.appendFile("data.txt", s+"\r");
          }
          digitalWrite(LED2,1);
      
        });  
        }
    
About

Avatar for Owen @Owen started