Hi,
I'm a newbie starting out with arduino / nano.
I need some simple GPIO ports that I can control from my PC -
Initially i thought of the PC parallel port but have decided against it -
I'm thinking maybe I can use a Nano v3, which would allow me to also use micro servos as well as GPIO.
- As I understand it - I will first need to program the Nano ( via usb I guess)
- once programmed - how can I read back the status of the GPIO on the nano ( in real time if possible) ?
I see some references to communicating to the nano by way of the PC serial port - but am not sure if this is for programming the nano or communicating to the nano after programming ( or both ?) ?
there is so much documentation on these device but I can get any definitive answer.
(NOTE: my larger plan is to write my own PC based application ( vb.net) that can communicate to the Servos / GPIO ports) - is this possible with Nano ?
many thanks
B.
" - As I understand it - I will first need to program the Nano ( via usb I guess) "
Correct.
" - once programmed - how can I read back the status of the GPIO on the nano ( in real time if possible) ?"
Have the Nano auto-send a message out when it sees a change. See below.
"I see some references to communicating to the nano by way of the PC serial port - but am not sure if this is for programming the nano or communicating to the nano after programming ( or both ?) ?"
Both.
byte portBpins; // bits 5-0
byte portCpins; // bits 5-0
byte portDpins; // bits 7-0, but 1 & 0 are the Serial comm pins
byte oldportBpins = 0x3F; // 00111111
byte oldportCpins = 0x3F; // 00111111
byte oldportDpins = 0xFF; // 11111111, Serial pins read back as High (1) when not in use
byte x;
void setup(){
for (x=2; x<20; x=x+1){
pinMode (2, INPUT_PULLUP); // set up pins as inputs with internal pullup resistor enabled
}
Serial.begin (115200); // make speed on PC side match - window in lower right of Serial Monitor for example
}
void loop(){
// read port B, see if any changed, send out if did
portBpins = PINB & 0x3F; // read and mask off the unused bits
if (portBpins != oldportBpins){ // compare current to old
oldportBpins = portBpins; // replace old value with new value
Serial.print ("D13-D8");
Serial.println (portBpins, HEX); // or BIN
}
// read port C, see if any changed, send out if did
portCpins = PINC & 0x3F; // read and mask off the unused bits
if (portCpins != oldportCpins){ // compare current to old
oldportCpins = portCpins; // replace old value with new value
Serial.print ("D19-D14");
Serial.println (portCpins, HEX); // or BIN
}
// read port D, see if any changed, send out if did
portDpins = (PIND & 0xFC) >>2; // read and mask off the unused bits
if (portDpins != oldportDpins){ // compare current to old
oldportDpins = portDpins; // replace old value with new value
Serial.print ("D7-D2");
Serial.println (portDpins, HEX); // or BIN
}
}
That should be pretty close.
"(NOTE: my larger plan is to write my own PC based application ( vb.net) that can communicate to the Servos / GPIO ports) - is this possible with Nano ?"
Yes, similar to the above. Incorporatet the Servo.h library, develop a message protocol for how you will specify a servo on a particular channel (or pin) and what position you are commanding it to, then have the Servo library move it to that position.
Thanks CrossRoads,
just one additional thing I'm not 100% sure about ..
So the nano has a micro usb connection ...
Will this show up on my PC as a COM port ? ( example COM5)
and so I would send my initial program to the nano by way of COM5 ?
and then when the program is loaded to the nano and it's up and running ... do I then listen to the same COM5 to get my responses back ?
or are there physically different com ports for programming and communicating ?
thanks again
regards
"So the nano has a micro usb connection ... "
On a clone.
Arduino Nano uses a mini-USB as far as I know. https://www.arduino.cc/en/Main/ArduinoBoardNano
Clone is also likely to use CH340G for the USB/Serial interface, vs Arduino using FTDI FT232, so you may have to find a CH340 driver also. FT232 driver can be found at www.ftdichip.com if it's not included in the arduino/driver folder.
Yes, COM5 all the way thru per your example. No difference for serial download and communicating.
The upper left arrow in the IDE is to Compile the code only, the next over compiles & downloads.
Over on the upper right is a magnifying glass looking button, that opens the Serial Monitor to interact with the sketch.
The same can be found as commands under the various menu words.
thanks again ,
so what are the TX and RX pins on the nano used for ?
are they physically the same connection points as the tx / rx on the micro usb connector or are they a different serial port again ?
thanks
Rx & Tx are connected to the USB/Serial chip via 1K resistors.
If the Nano is not connected to a PC, the pins can be used to connect to external devices with a serial interface, or as regular digital IO pins for other uses.
Perfect !! - thanks very much for your help
best regards