Pages: [1]   Go Down
Author Topic: Arduino Robot: How to use digital input/output  (Read 501 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just recently got an arduino robot, and I am trying to setup an ultrasonic sensor. This sensor needs a digital I/O port. With the arduino robot  the docs day to change the signal via:

Robot.digitalWrite(TKD1, LOW);
  delayMicroseconds(2);
  Robot.digitalWrite(TKD1, HIGH);
  delayMicroseconds(5);
  Robot.digitalWrite(TKD1, LOW);

After some further testing it appears that the port's signal is never going to LOW, even when I just run a blank program with this code:

#include <ArduinoRobot.h>
void setup(){
  Robot.begin();
}

void loop(){
  Robot.digitalWrite(TK0, LOW); // Turn the LED off
  delay(1000);
}

the pins are all still live with the code above. What do I have to change to make these pins turn off?


* Screen Shot 2014-08-07 at 6.34.44 PM.png (110.7 KB, 490x348 - viewed 15 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I have exactly the same problem: connecting the US sensor to an Arduino UNO using pin 7 everything works fine.
Changing to Arduino Robot using D8 the distance is always 0.
I can post the code, but I think the code is not the problem.
The question is shown above: How to use digital input/output and what is the right connection: where is GND, +5V and Signal on e.g. D8? Link to documentation?
Thank you in advance for help!
Ingeborg
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a link to some docs: http://fabcirablog.weebly.com/blog/grappling-with-the-arduino-robot-control-board but i am unsure how to make sense of them.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello again!
Thank you for the link! This shows me, that the documentation is really poor.
I wonder why noone of the mods is helping us!

In the meantime I tried the following (using a breadboard, a resistor and a LED):
Using Arduino with pin7: blinks!
Connect a LED with a resistor to D8: GND to the GND and the Source to + 5 V: LED is always on (ok).
Connect the Source to the middle pin an uploading the following code:
Code:
#include <ArduinoRobot.h>
#include <Wire.h>
#include <SPI.h>
int led = D8; //
void setup() {
  pinMode(led, OUTPUT);
}

void loop() {
  Robot.digitalWrite(led, HIGH);
  delay(500);
  Robot.digitalWrite(led, LOW);
  delay(500);
}
And Surprise: nothing happend!
I'm really frustrated, because AllIOPorts (the Example of ArduinoRobot) uses the same code.
So what is wrong? Why has nobody else the same problem?
I hope that someone can help us!?
Ingeborg
« Last Edit: August 11, 2014, 05:12:47 am by Ingeborg » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I forgot the "Robot.begin();" in the setup. But after inserting nothing changed the problem....
Ingeborg
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27115
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This code:
Code:
#include <ArduinoRobot.h>
void setup(){
  Robot.begin();
}

void loop(){
  Robot.digitalWrite(TK0, LOW); // Turn the LED off
  delay(1000);
}
is missing this in setup:
pinMode (TK0, OUTPUT);
unless Robot.begin(); sets it up.

I don't have this library, ArduinoRobot.h, I don't know what it does.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#include <ArduinoRobot.h>
#include <Wire.h>
#include <SPI.h>
int led = D8;
void setup() {
  Robot.begin();
  pinMode(led, OUTPUT);
}

void loop() {
  Robot.digitalWrite(led, HIGH);
  delay(500);
  Robot.digitalWrite(led, LOW);
  delay(500);
}
This is the code. But is don't work.
Ingeborg
Logged

BZ (I)
Offline Offline
Brattain Member
*****
Karma: 266
Posts: 21659
+39 349 2158303
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/en/Reference/RobotLibrary
http://arduino.cc/en/Reference/RobotDigitalWrite

I think that D8 is not a usable I/O Pin. You must use on of the Pins TKD0 to TKD5. Pleas see board description at http://arduino.cc/en/Main/Robot

Bye Uwe
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Below is the code that should make an external led blink. But for some reason all of the Digital I/O pins seem to always be off and never going to low. I have tries the other Digital ports to make sure it wasn't an issue of me assigning the wrong port. Is the problem with the hardware or what?

Code:
#include <ArduinoRobot.h>
void setup(){
  Robot.begin();
}

void loop(){
  Robot.digitalWrite(TKD1, HIGH);
  delay(1000);
  Robot.digitalWrite(TKD1, LOW);
  delay(1000);
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi alexpell00,
how did you connect the LED to port TKD1? Soldering? There are only holes on the board.
Code:
pinMode(TKD1, OUTPUT);
is missing in the setup.
Ingeborg

Hi Uwe,
why can't D8 be used for Digital Output? +5V and GND are set (a connected LED is ON). The middle pin should be the signal pin (as far as I understand TinkerKit connection).
Ingeborg
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I will try and add the output, I am using the correct pin I think. But I have tried all 15 pins in that cluster to see if I had the wrong one.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a working code with D0 on the top board:
Code:
//Led.ino 14.08.2014
//Connect a LED to D0 middle= +, right= - (GND)
//D0 printed on the board is near to - resp. GND
//It is not recommended to use a LED without a resistor
//but it works for testing purposes

#include <ArduinoRobot.h>
#include <Wire.h>
#include <SPI.h>

int led = D0;
void setup() {
  //Robot.begin(); // not necessary for this test
  pinMode(led, OUTPUT);
}

void loop() {
  Robot.digitalWrite(led, HIGH);
  delay(500);
  Robot.digitalWrite(led, LOW);
  delay(500);
}

Ingeborg

Source code (Sensors.cpp) shows that the bottom ports are used for motor purposes.

And here is a working code for the Seeed US distance sensor (digital signal):

Code:
/***************************************************************************/
// Function: Measure the distance to obstacles in front and print the distance
//   value to the serial terminal.The measured distance is from
//   the range 0 to 400cm(157 inches).
// Hardware: Ultrasonic Range sensor
// Arduino   IDE: Arduino-1.5.7
// Author:   LG
// Date:   Jan 17,2013
// Version:  v1.0 modified by FrankieChu
//                v1.1 modified by Ingeborg 14.08.2014
// by www.seeedstudio.com
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
/*****************************************************************************/
#include <ArduinoRobot.h>
#include <Wire.h>
#include <SPI.h>

int pin = D1;

class Ultrasonic
{
    public:
        Ultrasonic(int pin);
    void DistanceMeasure(void);
        long microsecondsToCentimeters(void);
        long microsecondsToInches(void);
    private:
        int USpin;//pin number of Arduino connected with SIG pin of US Sensor.
        long duration;// the Pulse time received;
};
Ultrasonic::Ultrasonic(int pin)
{
        USpin = pin;
}
/*Begin the detection and get the pulse back signal*/
void Ultrasonic::DistanceMeasure(void)
{
        pinMode(USpin,OUTPUT);
        Robot.digitalWrite(USpin, LOW);
delayMicroseconds(2);
Robot.digitalWrite(USpin, HIGH);
delayMicroseconds(5);
Robot.digitalWrite(USpin,LOW);
pinMode(USpin,INPUT);
duration = pulseIn(USpin,HIGH);
}
/*The measured distance from the range 0 to 400 Centimeters*/
long Ultrasonic::microsecondsToCentimeters(void)
{
return duration/29/2;
}
/*The measured distance from the range 0 to 157 Inches*/
long Ultrasonic::microsecondsToInches(void)
{
return duration/74/2;
}
 
Ultrasonic ultrasonic(pin);
void setup()
{
        Robot.begin();
Serial.begin(9600);
}
void loop()
{
long RangeInInches;
long RangeInCentimeters;
ultrasonic.DistanceMeasure();// get the current signal time;
        RangeInInches = ultrasonic.microsecondsToInches();//convert the time to inches;
RangeInCentimeters = ultrasonic.microsecondsToCentimeters();//convert the time to centimeters
Serial.println("The distance to obstacles in front is: ");
Serial.print(RangeInInches);//0~157 inches
Serial.println(" inch");
Serial.print(RangeInCentimeters);//0~400cm
Serial.println(" cm");
delay(1000);
}

So I must buy a soldering iron, because D0 etc are only holes.. smiley-mad
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://imgur.com/v62dkSh

 Am i doing something wrong with the wiring? I still can't seem to get this light to blink. Here is my code:

Code:
#include <ArduinoRobot.h>
//I had to remove the other two imports because it crashed the compile. I am pretty sure arduinorobot.h already includes them

int led = TKD0; //also it said pin D0 was invalid so I had to change it to a valid pin
void setup() {
  //Robot.begin(); // not necessary for this test
  pinMode(led, OUTPUT);
}

void loop() {
  Robot.digitalWrite(led, HIGH);
  delay(500);
  Robot.digitalWrite(led, LOW);
  delay(500);
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I can see from your picture/video that you connect the led to the left and the right "hole". So it should always blink! Take the plus to the middle and see what happens.
I will check if it is really necessary to include Wire.h and SPI.h. But it should be possible to include them because they are needed to start the motors (as far as I know (didn't test it).
Ingeborg
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes it is necessary to include the 2 h files. In my case the is no compilation!!
Perhaps you install the Arduino IDE new??
Ingeborg
Logged

Pages: [1]   Go Up
Jump to: