PDA

View Full Version : [Question(s)] How conect micro SD card with ArbotiX-M



urko_18
03-06-2018, 02:30 AM
Hello everyone!!


I wanted to ask if anyone knows if it is possible to connect a micro SD card with the ArbotiX-M.


My goal is to save more movements of some servos in order to move a robotic arm, since I have the SRAM memory of the arbotix completely full.


Thank you!!


Urko

urko_18
03-07-2018, 06:02 AM
I've been researching and I think maybe this connection could be made through the ISP pins, but I do not know exactly ... is there someone who can help me?


For example to connect the micro SD reader to the UNO arduino, the following scheme is used:
http://www.naylampmechatronics.com/modules//smartblog/images/38-single-default.jpg

But I still do not know how to connect it to the ArbotiX-M (I have a micro SD reader similar at one of the image)


Thank you,

Urko.

KurtEck
03-07-2018, 08:52 AM
I do think it is possible... Personally it might be easier using a different controller, like OpenCm9.04 for about $20 which has I think twice the program space and maybe 5 times the RAM... More Speed, more Uarts... And as you may have seen on this forum I do like Teensy boards by PJRC...

But to answer your question. Yes you can probably hook up a MicroSD adapter, like the one from SparkFun:
https://www.sparkfun.com/products/13743

Which is a pretty basic setup, it has a voltage regulator built in to convert 5v to 3.3v, plus ttl level converters to change the Arbotix-m 5v signals into 3.3v signals...

You should read through the hook up guide for this: https://learn.sparkfun.com/tutorials/microsd-breakout-with-level-shifter-hookup-guide

And then translate the IO pins from what where SPI is on the Arduino to where it is on the Arbotix:

If you looks that the pins_arduino.h as part of Arbotix installation, you will see some definitions like


const static uint8_t SS = 4;
const static uint8_t MOSI = 5;
const static uint8_t MISO = 6;
const static uint8_t SCK = 7;

Which show you the SPI pins on the Arbotix... Which if you look at the pin definitions for a simple Arduino you will see:


#define PIN_SPI_SS (10)
#define PIN_SPI_MOSI (11)
#define PIN_SPI_MISO (12)
#define PIN_SPI_SCK (13)

static const uint8_t SS = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;

So that should hopefully give you some hints on how to translate the pins...

Once you have it hooked up electrically you will then need a library like the SD library to talk. If you are still using the default Arbotix installation of Arduino 1.0.4, not sure if or how well these libraries work. So hopefully you are on a more recent Arduino IDE like 1.8.5!

urko_18
03-12-2018, 04:37 AM
Thank you KurtEck!!

Okey, during theese days i was trying to implement what you say but i didn´t get results... The ISP module of the arbotix is like this image:

7181
So, I understand that I should connect the MOSI, MISO, GND, VCC and SCK pins in a normal way to the micro SD card reader, and then do what you tell me:

static const uint8_t SS = PIN_SPI_SS;for the SS pin, right?


If not, tell me and I will try to correct it! thank you very much!!!!!

Urko.

urko_18
03-12-2018, 05:43 AM
I think I discover the SS pin in the ArbotiX-M, in the PB4 port, so, i will try to do with this pin.
I was looking in the datasheet of the ATmega644P.

http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42744-ATmega644P_Datasheet.pdf

Urko.

KurtEck
03-12-2018, 10:42 AM
Note: with most libraries, I am not really sure how important it is to get the hardware CS pin... It has been a long time since I did it with an AVR board and I believe there were in some cases issues if the hardware CS pin was not enabled, but for the actual CS pin code, most libraries simply use a standard digital pin to control the chip select to the actual device (pinMode(pinX, OUTPUT), digitalWrite(...)

And most libraries try to make sure that the hardware stuff is taken care of.

If you look at the Arbotix-m Schematic: http://learn.trossenrobotics.com/images/tutorials/arbotixM/arbotixM-schematic.pdf

You will notice that the different SPI pins are also wired to some standard digital pins like D5-D7... SO you can hook up to those as well.

Even if you don't use those pins to connect, you can NOT use those pins for anything else as they are logically the same and connected to each other.

jwatte
03-12-2018, 11:29 AM
Hardware CS is only important in two cases:
1) when being a SPI slave
2) when doing fancy DMA-driven high-speed communication

The Atmegas can't do 2) and you're not doing 1) in this case so it's not necessary in this case.

urko_18
03-13-2018, 05:31 AM
Thanks for answering!! more or less I have managed to understand and find out which pins the MISO, MOSI, SCK and SS refers to:

SCK/PCINT15 – Port B, Bit 7– SCK: Master Clock output, Slave Clock input pin for SPI0 channel. When the SPI0 is enabledas a slave, this pin is configured as an input regardless of the setting of DDB7. When theSPI0 is enabled as a master, the data direction of this pin is controlled by DDB7. When thepin is forced to be an input, the pull-up can still be controlled by the PORTB7 bit.– PCINT15: Pin Change Interrupt source 15. The PB7 pin can serve as an external interruptsource.

MISO/PCINT14 – Port B, Bit 6– MISO: Master Data input, Slave Data output pin for SPI channel. When the SPI0 is enabledas a master, this pin is configured as an input regardless of the setting of DDB6. When theSPI is enabled as a slave, the data direction of this pin is controlled by DDB6. When the pin isforced to be an input, the pull-up can still be controlled by the PORTB6 bit.– PCINT14: Pin Change Interrupt source 14. The PB6 pin can serve as an external interruptsource.

MOSI/PCINT13 – Port B, Bit 5– MOSI: SPI Master Data output, Slave Data input for SPI channel. When the SPI0 is enabledas a slave, this pin is configured as an input regardless of the setting of DDB5. When the SPIis enabled as a master, the data direction of this pin is controlled by DDB5. When the pin isforced to be an input, the pull-up can still be controlled by the PORTB5 bit.– PCINT13: Pin Change Interrupt source 13. The PB5 pin can serve as an external interruptsource.

SS/OC0B/PCINT12 – Port B, Bit 4– SS: Slave Port Select input. When the SPI is enabled as a slave, this pin is configured as aninput regardless of the setting of DDB4. As a slave, the SPI0 is activated when this pin isdriven low. When the SPI is enabled as a master, the data direction of this pin is controlled byDDB4. When the pin is forced to be an input, the pull-up can still be controlled by thePORTB4 bit.– OC0B: Output Compare Match B output. The PB4 pin can serve as an external output for theTimer/Counter0 Output Compare. The pin has to be configured as an output (DDB4 set “1”) toserve this function. The OC0B pin is also the output pin for the PWM mode timer function.– PCINT12: Pin Change Interrupt source 12. The PB4 pin can serve as an external interruptsource

And I understand that each pin can get to behave in different ways or forms, for example the Port B, Bit 6, can be the MISO or an interruption. What I do not know is how to configure it, that is, what code should be set to work as MISO, MOSI, SCK and SS instead of pins with interruption for example ... I mean, I can not put only pin (4) to refer to the pin of the SS no?

Other question, i have to configurate the arduino.h library? because as yo have sayd to me KurtEck, in this library i know that the following code appear:



#define PIN_SPI_SS (10)
#define PIN_SPI_MOSI (11)
#define PIN_SPI_MISO (12)
#define PIN_SPI_SCK (13)

static const uint8_t SS = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;

But i don't know if i have to configure this library and i don´t know neither if there exists a library of arbotix.h...do anyone know?

tician
03-13-2018, 06:13 AM
The SPI library is part of hardware/avr/... (platform specific) libraries and the SD library is part of the global Arduino libraries. If you are using Arduino 1.8.x and the board manager with my pathetic attempt (add https://tician.github.io/arbotix/package_trossen_arbotix_index.json to the board manager list in the preferences window), then you should only need to upgrade to v0.0.3 of the 'arbotix by tician' package, select the arbotix-m as your board, and run any of the SD library examples.

The arbotix uses:


static const uint8_t SS = 4;
static const uint8_t MOSI = 5;
static const uint8_t MISO = 6;
static const uint8_t SCK = 7;

so you only need to hook up the correct pins to the SD card and let the SPI and SD libraries do the rest. The examples may or may not require the 'Chip Select' pin to be defined as pin 4 or any other pin you choose to use as the SS/CS pin.

urko_18
03-13-2018, 07:51 AM
Sorry tician, but i don´t understand you very well, where did you say that i have to put this link and why? i don´t understand the text that the link open. Is like a configuration of the arbotix or?


Mi code right now is like this, (is a simple program that reeds the folder named "Prueba"):



#include <SPI.h>
#include <SD.h>
File myFile;


void setup()
{
Serial.begin(9600);
Serial.print("initializing SD ...");
if (!SD.begin(4)) {
Serial.println("It failed to initialize");
return;
}
Serial.println("successful initialization");

myFile = SD.open("Prueba.txt");//WE OPEN THE FILE
if (myFile) {
Serial.println("Prueba.txt:");
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close(); //WE CLOSE THE FILE
} else {
Serial.println("Error opening the file");
}
}


void loop()
{

}


And I have conected the wires like this:
MISO- digital 6
MOSI- digital 5
SCK- digital 7
SS- digital 4
VCC- ISP VCC
GND-ISP GND

I don´t know if i have to put more code to especificate that those pins are doing MOSI, MISO... work or what...

The program runs, but in the serial monitor they is only appearing this:

"initia⸮ initia⸮ initia⸮ " And i don´t know why...

Also, the micro SD card reader does not even turn on the led...

KurtEck
03-13-2018, 09:18 AM
What Tician was mentioning, is that ... First some background.

The officially released Trossen Arbotix-M stuff was released for Arduino 1.0.4 if I remember the correct 1.0.x... Which is ancient. I later tried to get them migrated over to more recent builds including now the 1.8.5 Arduino (Current release). They had a Beta setup to try it out, before the person doing the Beta left the company... During that time frame, @tician, did the work necessary to make it easier to install the Arbotix stuff, using the Arduino Board Manager stuff. This is the same way you add in special boards from Adafruit, or Sparkfun or Robotis, or ...

So to add a new board type to Arduino, that Arduino as not pre-packaged into the release, you do the following:

You start up Arduino. And you bring up the preferences dialog. In this dialog, maybe 3/4 of the way down you will see an item: Additional Boards Manager URLs:

Where you enter (or add separated by commas)

https://tician.github.io/arbotix/package_trossen_arbotix_index.json
Note: I don't feel this is pathetic at all, but what is unfortunate is that Trossen has not picked this up and if necessary made a few minor changes, like maybe add a few more libraries and made an official location...

Then you OK out the dialog.

You then go to the Tools->Boards menu item and choose the Board manager. Somewhere down in that list (probably near the end, you will see the Arbotix AVR Boards by tician, which you can click on the info and choose to do the install...

Now back to your code..

A couple of things. First off I assume that you had which ever version of the IDE you were trying actually successfully download the program to your Arbotix.

I assume that you have board type set to the Arbotix-m and you have the Port set to the correct port (the one associated with the Arbotix-m board).

I also assume that when you opened the Serial monitor, that you choose the baud rate of 9600 to match the baud rate you specified in the program above.

Note: I would also maybe put in a delay at the start of the program to make sure that the serial captures the data. Like maybe a delay(1000); right after the Serial.begin()...

And yes I believe the SD.begin will call through to SPI.begin(), which will initialize the proper state for each of the SPI pins. I believe the 4 passed into it is the CS pin, which it will also initialize to the correct state.

I am also assuming that the SD device you have, probably includes Pull UP resistors for some of the SPI pins, like MISO pin? I don't remember if you put in a link to the actual hardware device you are using.

urko_18
03-13-2018, 09:24 AM
Sorry i didn´t realiz that you have answered,
Thank you!!

Ok, I have installed that URL that you told me, and now I get two new plates to choose from:
-Arbotix m
-Arbotix w / RX shield

7183
Is alright?

Continuing, I have a micro SD reader that I came across by chance, I sent a link with the photo of the reader's connection to an arduino UNO, it is the following:
http://www.naylampmechatronics.com/m...le-default.jpg

First off I assume that you had which ever version of the IDE you were trying actually successfully download the program to your Arbotix.
-Yes i have succesfully download, and my IDE is the 1.8.5

I assume that you have board type set to the Arbotix-m and you have the Port set to the correct port (the one associated with the Arbotix-m board).
-Yes, that is!

I also assume that when you opened the Serial monitor, that you choose the baud rate of 9600 to match the baud rate you specified in the program above.
-Yes is set like that.

Whar I don´t know if the micro SD reader has resistenace, but I doubt it a lot, since i do not see more than one r1, how could I solve that?


Many thanks!

Urko.

KurtEck
03-13-2018, 10:05 AM
Again what version of Arduino? What SD library... Do you have an SD card in the reader? Is it initialized and formatted? If so what is it formatted as? FAT?

If it failed to initialize, I would tend to look in the SD library at the begin code and see if you can add or enable additional Serial outputs to localize down what failed...

urko_18
03-13-2018, 10:30 AM
I have edit my last post because i didn´t realize that you had answered me, sorry.

Yes i have a SD card in the reader, and yes, my SD was formatted by using SD Card Formatter program.

Okey I will try to look in the SD library!

Thanks,

Urko.

urko_18
03-15-2018, 02:57 AM
Hellow another time!:happy:

I continue trying to implement this conection, my last attempt was this: (i change the name of the pin, because i know that the pin of SS is the 4 one of the port B of the arbotix)



#include <SPI.h>
#include <SD.h>
File myFile;


#define PIN_SPI_SS (PINB & 0x04)
const int chipSelect = PINB & 0x04;
void setup()
{
Serial.begin(9600);
delay(1000);
// PORTB |= 0x1E;
// PCICR |= (1 << PCIE1);
// PCMSK1 |= 0x1E;
pinMode(PINB & 0x04, OUTPUT);
Serial.print("initializing SD ...");
if (!SD.begin(chipSelect)) {
Serial.println("It failed to initialize");
return;
}
Serial.println("successful initialization");

myFile = SD.open("Prueba.txt");//WE OPEN THE FILE
if (myFile) {
Serial.println("Prueba.txt:");
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close(); //WE CLOSE THE FILE
} else {
Serial.println("Error opening the file");
}
}


void loop()
{

}




But the program do the same than before...
maybe is because of the internal resistance of the micro SD reader? as KurtEck has said?
How can I solucionate this problem?

Thanks!

Urko.

KurtEck
03-15-2018, 09:16 AM
Right now, not sure what you are trying?

I am pretty sure the chip select information you pass into SD.begin is an Arduino pin number... It does not care what port or the like it is on... The slight caveat to this statement is that maybe internally it may decide to map the pin number to a port and a mask to use as a speed up, but that would be internal to the library.

Again things I would do would include figure out where the SD.begin() if failing.

If you look at the code you will see something like:

boolean SDClass::begin(uint8_t csPin) {
/*

Performs the initialisation required by the sdfatlib library.

Return true if initialization succeeds, false otherwise.

*/
return card.init(SPI_HALF_SPEED, csPin) &&
volume.init(card) &&
root.openRoot(volume);
}
So you know it is failing in one of the three calls... You might add Serial.print statements in the functions called to see what is going on... Or you could add more info to this code like:

boolean SDClass::begin(uint8_t csPin) {
/*

Performs the initialisation required by the sdfatlib library.

Return true if initialization succeeds, false otherwise.

*/
if (!card.init(SPI_HALF_SPEED, csPin)) {
Serial.println("Card Init Failed");
return false;
}
if (!volume.init(card)) {
Serial.println("Volume Init Failed");
return false;
}
if (!root.openRoot(volume)) {
Serial.println("Open Root Failed");
return false;
}
return true;
}

Note: Typed in on the fly so could be issues... Once you figure out which of these fail, you can then go into where these functions call off to and figure out where that fails...

urko_18
03-19-2018, 08:40 AM
I tried this morning to write what you have put me in the library of the SD.h, but when I run the program, the same message has appear in the serial monitor, that te SD fails to initialize, without specifying any of the three options (root, volume, card) ...


The truth is that I do not know what else to try ... I have reviewed all the connections more than once and they are fine, and two or three weeks ago I wrote to the email of vanadiumlabs about the problem, but they have not answered me.


Urko.

KurtEck
03-19-2018, 10:21 AM
Make sure you are editing the version of the SD library that is being used...

That is, check your build. If there are multiple versions of a library, it will usually give message like, using this library and not using that library. For the heck of it, I would also add something like: Serial.println("SD Begin called");
right at the start of that function, which again should print something. Else it is not being called!

and/or check to see if there are multiple begin methods, that may depend on what type of architecture the board is... In your case AVR, but there may be some other portions of code for different ARM boards like for DUE and M0...

As for vanadiumlabs I am not sure they really exist anymore. I believe the Arbotix-m was done by Tyberius (Andrew) who I believe is no longer working with Trossen... You might try emailing support at Trossen, but my gut tells me that they may direct you back to the forum...

urko_18
03-21-2018, 06:19 AM
Yes, I'm sure I'm in the correct version but, I do not know what happens that does not connect well ... i had put what you say of "SD Begin called" but also didn´t appear..


Thanks KurtEck, I will send an email to trossen, to see if I am lucky and they respond to me although I also believe that they will send me here hahaha


At the moment I'm going to put aside this problem of have little memory space in the ArbotiX-M, and I'll be working on it later!


Now I'm going to focus on the torque control of my robot, which I have already asked some time ago in some threads and I have forgotten it ...


And of course, Thank you very much to all of you for the advices that you have been giving me !!!!!


If I ever connect the SD with the ArbotiX-M I will let you know through this forum and I will explain it here too !!




Urko

KurtEck
03-21-2018, 09:54 AM
Normally if the message did not display and nothing else displayed after that, I would say that maybe the code hung... But you say the message after that call did display, so it obviously did not hang...

If nothing else displays, I then typically, go to where I did the Serial.println and add a Serial.flush()

Something like:
Serial.println("SD Begin Called"); Serial.flush();

This causes the code to wait and send the current cached Serial data and wait for that to complete before continuing... You might want to try that here as well any way...

If you still don't see any of these messages, than the code is almost for sure not being called! Sometimes when I get strange compiling issues, I might add a garbage line to the code in the suspected function:
Like: This is Garbage

And then try to build. If it does not give you a compile error, than that code is not included in the build...

Also might help to know which version of SD library you are using. If you are using the one from Arduino, that comes from:
https://github.com/arduino-libraries/SD

Note: This is not the version I personally use as I use the version for Teensy boards but...
If you use the Arduino version, then you will notice that there are at least two ::begin methods

boolean SDClass::begin(uint8_t csPin) {
if(root.isOpen()) root.close();

/*

Performs the initialisation required by the sdfatlib library.

Return true if initialization succeeds, false otherwise.

*/
return card.init(SPI_HALF_SPEED, csPin) &&
volume.init(card) &&
root.openRoot(volume);
}

boolean SDClass::begin(uint32_t clock, uint8_t csPin) {
if(root.isOpen()) root.close();

return card.init(SPI_HALF_SPEED, csPin) &&
card.setSpiClock(clock) &&
volume.init(card) &&
root.openRoot(volume);
}

So the question would be did you update the one you are actually calling? Again assuming the garbage code prints out an error message, than I would then make sure to put some comment in every ::begin to see which one (if any) is called.

Also side note: if it were me, unless I really really wanted to use SDCard... it would probably be a lot easier, just to switch over to using something like the OpenCM904. There are a few issues with the 904C in that they don't have any AX servo connections (xl320 type instead), which can be solved a few different ways. Buy the 904A (no connectors) and the connector kit which has both XL320 and AX servo connector types so you can solder in AX connectors... Or you can simply jumper one of the XL320 connectors to an AX powered hub and then go from there... Or you could use the 904C plugged into the RS485 module which has AX TTL level connectors as well as the RS485 connectors... Probably a lot less hassle!

On the other hand if it was really just me, would say use a Teensy by PJRC (https://www.pjrc.com/teensy/techspecs.html). If you use the T3.5 or T3.6 they have an SDCard built into them, let alone lots more memory, speed...

tician
03-21-2018, 02:30 PM
If you add debug messages that should always print out when a library function runs but it does not appear, then you are not modifying the correct copy of the library (very likely) or the library is not being rebuilt (rather difficult to achieve when using arduino).

If you are using the board manager, then modifications should only and always be made to the contents of the '/home/.arduino15/packages/arbotix/' folder tree. That is where the arbotix-m installation is located on linux and should be in a very similar location on windows.

KurtEck
04-02-2018, 05:09 PM
For what it is worth, I was making an order to sparkfun and needed a couple $ more for free shipping, so picked up microSD breakout:
https://www.sparkfun.com/products/13743

I then hooked up the adapter using similar pin numbers as mentioned in #10 Also added pin 3 for the other pin which I believe can detect if sd is inserted or not.

Pictures showing hookup:
71937194

Again your program:


#include <SPI.h>
#include <SD.h>
File myFile;


void setup()
{
Serial.begin(9600);
Serial.print("initializing SD ...");
if (!SD.begin(4)) {
Serial.println("It failed to initialize");
return;
}
Serial.println("successful initialization");

myFile = SD.open("Prueba.txt");//WE OPEN THE FILE
if (myFile) {
Serial.println("Prueba.txt:");
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close(); //WE CLOSE THE FILE
} else {
Serial.println("Error opening the file");
}
}


void loop()
{

}

I uploaded using FTDI (after I used AVR programmer to put bootloader back on)

Output from run:


initializing SD ...successful initialization
Prueba.txt:
Line 1
Line 2

Note: this was a brand new 16gb SD Card assuming probably FAT32 formatted. Soon to be RPI3 card for new RPI3 B+...

Note: for power I am using +5v/GND from the 3 pin header associated with D4...
Program is using the latest version of SD library

As you can see in some of the build warning information

Multiple libraries were found for "SD.h"
Used: C:\Users\kurte\Documents\Arduino\libraries\SD
Not used: D:\arduino-1.8.5\libraries\SD

Note: My SD library comes from: https://github.com/PaulStoffregen/SD

urko_18
04-09-2018, 03:16 AM
Hi KurtEck! Thank you for answer me another time!! Sorry but I was on holidays and I didn´t reed the message since today.

I already have proved this hookup and it´s okey!!!

the only difference between your conection and my conection was that i didn´t conect the pin 3, but know every thing is equal and the Micro SD card is recognised!!!

Why did you believe that the pin 3 allows to say if the SD is inserted or not??? I didn´t understand yet.

Another time, thank you!

Now, i will try to store the movements of the robotic arm in the SD card, in order to have much more SRAM memory!!

I will put here my advances!

Urko.

urko_18
04-24-2018, 07:31 AM
Hellow to everybody!

As I have said, I will put my advances:

During this two weeks I have worked in trying to save the movements of the sequences in the SD, and finally i have done, using the SD.h library (correctly).

Basically, I have used the followings codes and blocks:

First, to start the connection between the SD and the PC-Arduino:


Serial.print("Iniciando SD ...");
if (!SD.begin(4)) {
Serial.println("No se pudo inicializar");
return;
}
Serial.println("inicializacion exitosa");


Second, i have use the following code to open/create a file and to save there the movements of the servos and them to close the file:


myFile = SD.open("Prueba.txt", FILE_WRITE); // Note

if(myFile)
Serial.println("file is open");
else
Serial.println("Error opening the file");

...

int pos = dxlGetPosition(SERVO_ID[j]);
myFile.println(pos); //read and save the actual position
...
myFile.close(); //close the file


Third, I have add a new variable in the program (this variable datas come from the SD), and I have used like the variable of the position that I have put in the previous posts, to read you datas i have used myFile.parseint :



int pos_from_file[servo_count];
...
pos_from_file[i] = myFile.parseInt();


And finally this block to delete the file at the end of the program:


if (SD.exists("Prueba.txt")) { // SI EXISTE EL ARCHIVO
SD.remove("Prueba.txt"); // ELIMINAR ARCHIVO
Serial.println("SD FILE REMOVED");
} else {
Serial.println("THE FILE DOESN´T EXIST");
}