Serielle Kommunikation @ Arduino UNO & VB.Net


hallo leute,

ich stehe im moment ein wenig auf dem schlauch. vielleicht zum einen weil ich noch kaum erfahrung mit dem arduino habe aber sicherlich auch, weil ich noch nie über vb.net auf den arduino zugegriffen habe.

was habe ich vor ...
ich habe mir das acs714 stromsensor breakout board +- 5a gekauft und möchte über den arduino einem gerät den strom messen.

den entsprechenden code dafür habe ich gefunden ...
code: [select]
/*
  computes average of sample of n readings @ intervals
  of 1000/n ms acs712 low current sensor connected to
  analog input pin 0 on arduino board , print them the
  serial monitor.
  sketch uses the chauvenet's statistical criterion
  rejecting bad readings.
*/

const int num_readings = 10;
// chauvenet's criterion rejecting reading
// http://people.ohio.edu/bayless/seniorlab/lecture1.ppt
// http://people.ohio.edu/bayless/seniorlab/chauvenet.pdf
// consult table of pdf document find ratio
// of maximum acceptable deviation precision index for
// sampling.
const int mad = 2.24;
int readings[num_readings];
int index = 0;

void setup() {
  // sets serial port 9600
  serial.begin(9600);
}

int average() {
  int total = 0;
  for(int i=0; i<num_readings; i++)
    total = total + readings[i];
  return total/num_readings;
}

float standard_deviation(int avg) {
  int total = 0;
  for(int i=0; i<num_readings; i++)
    total = total + pow((avg - readings[i]), 2);
  return sqrt(total/num_readings);
}

void loop() {
  // read analog input pin 0
  int reading = analogread(0);
  readings[index] = reading;
  // incrementing index
  index = index + 1;
  // if have been done 10 readings...
  if (index >= num_readings) {
    // set index 0
    index = 0;
    // compute average
    int avg = average();
    // compute standard deviation
    float std = standard_deviation(avg);
   
    float madstd = mad * std;
    float lowlimit = avg - madstd;
    float highlimit = avg + madstd;
   
    int count = 0;
    int total = 0;
    for(int i=0; i<num_readings; i++) {
      // check if values of readings within limits.
      if(readings[i] >= lowlimit && readings[i] <= highlimit) {
        total = total + readings[i];
        count = count + 1;
      }
    }
    // compute new average
    int newaverage = total/count;
    // send serial port (as ascii digits)
    serial.println(newaverage);
  }
  // wait 1000/num_readings ms next reading
  //delay(int(1000/num_readings));
}


der serial monitor liefert mir dann das folgende ergebnis... soweit gut!
code: [select]
512
512
510
511
511
512
511
511
511
511
511
512
510
.....


nun möchte ich mit meiner vb.net anwendung über den serialport genau diese zahlen abgreifen und da hänge ich nun fest. ich habe dazu schon einiges ausprobiert, aber leider ohne erfolg!

der code zum lesen schaut bei mir wie folgt aus...
code: [select]
dim sw new stopwatch
        dim swms long = sw.elapsedmilliseconds
        dim wert integer = 0
        sw.start()
        dim port new system.io.ports.serialport
        port
            .portname = "com3"
            .baudrate = 9600
            .parity = io.ports.parity.none
            .databits = 8
            .stopbits = io.ports.stopbits.one
            .handshake = io.ports.handshake.none
            .rtsenable = true
            .dtrenable = true
            .encoding = system.text.encoding.ascii
            .newline = vbcrlf
        end with

        port.open()
        do

            wert = port.readbyte

            richtextbox1.invoke(sub()
                                    richtextbox1.appendtext(wert.tostring)
                                end sub)

            dim v integer = cint(100 / 1023 * wert)
            backgroundworker1.reportprogress(v)
            dt.rows.add(sw.elapsedmilliseconds, wert)

            if backgroundworker1.cancellationpending then
                backgroundworker1.reportprogress(0)
                exit do
            end if
            wert = 0
        loop
        port.close()


das ergebnis in der richtextbox ist dann ...
code: [select]
494948131053494913105349501310534949131053494813105313105349491310534949131053494913105349481310534948131053495013105349491310534949131053494813105349481310534948131053494913105349501310534949131053494913105349491310534949131053494913105349491310534949131053494813105349491310534950131053494913105349...

weiß einer wie man da weiter kommt? besten danke!

49 49 48 13 10
53 49 49 13 10
53 49 50 13 10
53 49 49 13 10
53 49 48 13 10
als ashii kode interpretiert ist:
1 1 0 lf cr
5 1 1 lf cr
5 1 2 lf cr
5 1 1 lf cr
5 1 0 lf cr

grüße uwe


Arduino Forum > International > Deutsch (Moderator: uwefed) > Serielle Kommunikation @ Arduino UNO & VB.Net


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62