Lets print from an SD card…

As mentioned in my previous post, I have been having what I believe are some random stepper skips as a result of activity on my host machine that cause subsequent layers to become offset in random directions (X and Y) after successfully printing the first 6-8mm of height of a 20mm test cube. My Prusa i3 is correctly calibrated for movement in all axes and also for filament extrusion, however when say the screen saver wants to kick in, or some other background takes requires too much CPU, the communication to the printer slows right down and re-transmits go up and steps are missed.

To try and combat this issue I have decided to try printing from an SD card, however as soon as I upload the new firmware (only change in configuration.h is for changing ‘#define SDSUPPORT false’ to ‘true’) when I next connect to the printer, via Repetier Host, it now shows the extruder temperature as -20C as opposed to around +19 or +20C. This is the same regardless of whether or not the SD card unit is actually connected. Disabling the sdsupport setting and uploading firmware once again and everything goes back to normal.

The pins.h definition of the SDSS pin for a Sanguinololu is D31 (or A0, or physical pin 40), the Extruder thermistor uses A7 (or D24 or physical pin 33), the heated bed thermistor uses A6 (or D25 or physical pin 34) all as per the default wiring for a Sanguinololu board.

I do not believe I have a short on the board as I regularly use the ICSP connections for re-loading firmware and I have had the SD card working on this same board with a much older version of Marlin at some point in the past, plus this is pretty wide spacing for header pins with large gaps in between.

I raised this issue on the RepRap Forum and had a response from Repetier, the author of the firmware that I am using. He suggested, that this was likely to be a duplication of pin usage, and I have to say that I agree with him, however I cannot prove it.

He also gave me a piece of code to use to print out variable settings to the log interface of the Repetier Host software:


I used this in various forms throughout the firmware testing just about any variable I could think of but only managed to prove that they were all set correctly.

I tried using a separate variable of SDSUPPORT1 to replace SDSUPPORT in a number of source files to only enable parts of the code, this just proved to me where the issue was being manifested, and not the source of the problem.

I confirm that the call to sd.initsd() is what causes the extruder temperature to go to -20C. Preventing this call allows the extruder temperature to read normally, attempting to mount the SD card will then call the sd.initsd() function which in turn calls the fat.begin() function and immediately the card is initialized, the extruder thermistor goes to -20C.

I soldered up a second Sanguinololu board and connected up the thermistors and endstops, This new board exhibited exactly the same behaviour, so I believe that test pretty much ruled out a hardware issue. (This was not an entirely wasted exercise as I intend to use this second board in my laser cutter). For both boards, the SD card can be mounted and files can be seen on the card, which shows me that I also have the SD card wired up correctly, likewise for both boards, with SDSUPPORT set to ‘true’, the extruder temperature is permanently at -20C, and yet with SDSUPPORT set to ‘false’ the thermistor values show correctly.

I tried swapping the pins for the Extruder and Heated bed sensors and all that happened is that the Heated bed thermistor experienced the same issue, started reading -20C and again was disabled – this ties the issue to Analog pin 7 and a possible conflict with digital pin 7 (SCK).

I am not entirely convinced that the digital pin numbering for the physical pins 33-40 is correct, there are differing sets of information on the web as to how Arduino maps these pins, the pinout shown in pins.h shows physical pin 33 as Analog 7 and Digital 24, with numbers decreasing for Analog and increasing for Digital up to physical pin 40 which shows as Analog 0 and Digital 31.
shows a different pinout with physical pin 33 as Analog 7 and Digital 31, with numbers decreasing for both towards physical pin 40 which shows as Analog 0 and Digital 24.

I decided to try moving the SDSS pin definition to Digital 24 and something different happened – instead of going to -20C on mounting the SD card, instead it went to about 998C! still obviously wrong, but at least it is a different result, the thermistor signal pin has gone high as opposed to low.

Further checking of the pinouts and datasheet showed that the correct pin to be using for SS with an SD card is actually physical pin 5 (Digital 4), this is also presented on the Sanguinololu board but with the name of PWM/D12, the D12 is somewhat misleading as this is more likely to mean PCINT12, and in the schematic shows as PB4-PWM wihich again are other names for this pin as defined in the Atmel datasheet (PB4/SS/OC0B/PCINT12).

After moving the CS/SDSS pin to D4 (physical pin 5) all appears to be working correctly once again – the SD card can be accessed and both thermistors are sending sensible readings.

I have since performed a print from the SD card, and yes, the printer no longer exhibits any form of slow down, unfortunately it has not fixed my creeping.

In all, several days of tearing my hair out to make very little progress, although now I do not need to worry about my prints failing due to high CPU load or high I/O on my MAC.

Leave a Reply