moty
Published

Arduino Inputs Outputs on PC

VB6 app to connect Arduino Uno ports to Windows PC

BeginnerFull instructions provided8,874

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1

Software apps and online services

Arduino IO

Story

Read more

Schematics

pinout

Code

arduino to PC

Arduino
/*
 * IO
 * Created: 12/08/2017 23:34:47
 *  Author: moty22.co.uk
*/

unsigned char inByte=0, outByte=0;         //

// the setup function runs once when you press reset or power the board
void setup() {
    // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
    // initialize outputs 8-13 inputs 2-7 analogue A0-A3
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);          //
  
}

// the loop function runs over and over again forever
void loop() {
  unsigned char i;
  
   if (Serial.available() > 0) {
          // read the incoming byte:
      inByte = Serial.read();
      
      if(inByte < 128)
      {
        PORTB = inByte; //update digital outputs 8-13
      }
      if(inByte == 128) //128 = a request for update
      {
        Serial.write(lowByte(analogRead(A0)));  //send low byte of 10 bits analogue read
        Serial.write(highByte(analogRead(A0))); //send high byte of 10 bits analogue read
        Serial.write(lowByte(analogRead(A1)));
        Serial.write(highByte(analogRead(A1)));
        Serial.write(lowByte(analogRead(A2)));
        Serial.write(highByte(analogRead(A2)));
        Serial.write(lowByte(analogRead(A3)));
        Serial.write(highByte(analogRead(A3)));
          //read the 6 digital inputs 2-7 and put them in a byte
        for(i=0;i<6;i++){
        bitWrite(outByte, i, digitalRead(i+2)); 
        }
        Serial.write(outByte);
     }
   }
}

Credits

moty

moty

12 projects • 63 followers

Comments