Hi,
I'm programming a robot controlled by a RC, but when function SD.begin is loaded, RadioControl stop working.
This is my code:
#include <SPI.h>
#include <Wire.h>
#include <LSM303D.h>
#include <SD.h>
#include <NewPing.h>
int ch2 = 10;
int aile = 0;
int ch0 = 0;
int thro = 8;
int ch1 = 9;
int rudder = 0;
int ch3 = 11;
int elevator = 0;
const int pulseInDelay = 20000;
int m1 = 4;
int e1 = 5;
int e2 = 6;
int m2 = 7;
const int UltrasonicPin = 12;
const int MaxDistance = 500;
int bip = 0;
NewPing sonar(UltrasonicPin, UltrasonicPin, MaxDistance);
int accel[3];
int mag[3];
float realAccel[3];
float heading, titleHeading;
char rtn = 0;
File logFile;
File TempHumPres;
void setup() {
Serial.begin(9600);
pinMode(e1, OUTPUT);
pinMode(e2, OUTPUT);
pinMode(m1, OUTPUT);
pinMode(m2, OUTPUT);
pinMode(13, OUTPUT);
SD.begin(3)
}
void loop() {
lectura();
}
void lectura() {
//Aile
int rawValueCH2 = pulseIn(ch2, HIGH, pulseInDelay);
aile = map(rawValueCH2, 1093, 1860, -255, 255);
if (aile < -255)
{
aile = -255;
}
if (aile > 255)
{
aile = 255;
}
if (aile > -40.0 and aile < 40.0)
{
aile = 0;
}
Serial.println(aile);
//Elevator
int rawValueCH3 = pulseIn(ch3, HIGH, pulseInDelay);
elevator = map(rawValueCH3, 1100.0, 1676.0, -255, 255);
if (elevator < -255)
{
elevator = -255;
}
if (elevator > 255)
{
elevator = 255;
}
if (elevator > -40.0 and elevator < 40.0)
{
elevator = 0;
}
Serial.println(elevator);
delay(300);
}
system
September 5, 2018, 1:46pm
2
int ch2 = 10;
int ch3 = 11;
const int UltrasonicPin = 12;
Which Arduino are you using? On the UNO, the SPI pins, used to communicate with the SD card, are 11, 12, and 13, and pin 10 needs to be set as OUTPUT.
I'm using a Romeo BLE - Arduino Robot Control Board with Bluetooth 4.0:
system
September 5, 2018, 2:14pm
4
I'm using a Romeo BLE - Arduino Robot Control Board with Bluetooth 4.0:
You'll need to figure out which pins are the SPI pins, and NOT use them for other purposes.
Juraj
September 5, 2018, 2:27pm
5
It is Atmega328. comment #1 applies
So My SD card must not be in SPI?
system
September 5, 2018, 2:39pm
7
MarcGarcia:
So My SD card must not be in SPI?
I don't understand that question/statement.
You have no choice. The communication between the SD card and the Arduino, when using the SD library IS SPI, which means that you can't use the SPI pins for other purposes.
Juraj
September 5, 2018, 2:43pm
8
the
MarcGarcia:
So My SD card must not be in SPI?
SD card uses SPI. Not the adapter. There is no SD card without SPI. You can't use pins 11,12,14 and SD card slave select pin. and pin 10 must be used as OUTPUT. default SD slave select pin is 4. how is SD card adapter connected to the board?
I use SPI for the SD.
But my robot gets the RC orders perfect and when I run SD.begin stops recibing orders from my RC controler
Then I lose 8 pins no?
4 for the motors and 4 for the SD?
Juraj
September 5, 2018, 4:09pm
13
how is the SD card connected?
Juraj
September 5, 2018, 4:17pm
15
the ICSP header pins are the same pins as 11, 12, 13
So I can't connect anything in 10,11,12,13 no?
Juraj
September 5, 2018, 4:22pm
17
MarcGarcia:
So I can't connect anything in 10,11,12,13 no?
you can use pin 10 as OUTPUT
I can connect anything in pin 10 if I put it in output?
Juraj
September 5, 2018, 4:35pm
19
MarcGarcia:
I can connect anything in pin 10 if I put it in output?
yes.
this pin is slave select if the Atmega is a slave. if SPI is active and this pin is INPUT Atmega is slave. so it must be OUTPUT if SPI is used.