Arduino Robot: How to use digital input/output

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

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

Here is a link to some docs: Grappling with the Arduino Robot Control Board - GRAPPLING WITH ELECTRONICS but i am unsure how to make sense of them.

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:

#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

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

This 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.

#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

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

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?

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

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

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

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.

Here is a working code with D0 on the top board:

//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):

/***************************************************************************/	
//	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.. :0

Imgur

Am i doing something wrong with the wiring? I still can't seem to get this light to blink. Here is my 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);
}

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

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