Showing posts with label SD Card. Show all posts
Showing posts with label SD Card. Show all posts

Saturday, 19 July 2014

Duet, 20x4 LCD screen and SD card.

Although the Duet communicates over Wifi and I can connect to it with a web browser on my phone, I still get many requests for a LCD based controller. I agree that being able to use a simple controller for quick, common functions is a good idea, things like homing the printer, preheating, starting a print etc. Think3dPrint3d have been providing controllers for older electronics that do this since we started, first with the Panelolu then with the Panelolu2 so it's time to port this to the Duet.

I decided to keep it simple to start with, so rather than get the Panelolu2 working, which would require I2C and headaches with 3.3V and 5V logic, I started with the PanelOne, a very basic LCD, Encoder, SD card combination which we are using on our Kossel Mini Kits.

Using a 5V LCD with 3.3V Microprocessor

This was the first hurdle to overcome. The HD44780 standard that these character LCD displays work on states 2.7 to 5V should work fine for the logic signals, however the LCD screens incorporating these chips are a lot more restrictive: 4.8-5.2V for the logic signals. Given the conflicting information I decided to modify a PanelOne prototype board by hand and give it a go. The key is to keep the logic signals separate from the backlight voltages. The schematic is below:



The major change is the addition of the "VCC" power into pin 2 of the LCD from pin 8 of header P1. Previously this was a straight 5V, now this should be able to be either 5V or 3.3V depending on the logic of the Microprocessor we are interfacing with. I connected this up and edited the "Hello World" sketch within Arduino 1.5.7 (1.5.6 r2 works as well) to use the following pin definitions:
/*
                            Arduino pin number  Duet Pin Name  Expansion header pin
 * LCD RS pin to digital pin D67                 PB16          (32)
 * LCD Enable pin to digital D23                 PA14          (10)
 * LCD D4 pin to digital pin D19                 PA10 RXD0     (14)
 * LCD D5 pin to digital pin D18                 PA11 TXD0     (13)
 * LCD D6 pin to digital pin D17                 PA12 RXD1     (12)
 * LCD D7 pin to digital pin D16                 PA13 TXD1     (11)
*/
LiquidCrystal lcd(67, 23, 19, 18, 17, 16);

Happily this worked!




I tested this with two other LCDs (old generic ones off eBay) and it worked with them as well. However as it's outside the guidelines of the LCD manufacturer's datasheets there is no guarantee that all types of HD44780 character LCDS will work in the same way.

Reading an SD card over SPI

The Duet's build in SD card supports SD2.0 and uses a 4 bit HSMCI interface. However it is often convenient to use an SD card reader mounted next to the screen, so I want to support SD over SPI which is how older 3D printer electronics and hardware interface with SD cards. The Arduino environment has a simple SPI SD library that worked straight away. The only customisation required is to make sure SD.Begin() uses the correct CS pin:

SD.begin(77);

For this example I used the SPI0_NPCS0 pin which is arduino digital pin 77. I combined the listfiles example sketch with the LCD display to list the first 4 files on a SD card:






The code (an adaptation of the listfiles example sketch):


#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal.h>

File root;
// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(67, 23, 19, 18, 17, 16); //RS,E,D4,D5,D6,D7

void setup()
{
  lcd.begin(20, 4);
  lcd.print("Reading Files...");
  delay(2000); //delay or else the message will not be displayed

  if (!SD.begin(77)) {
    lcd.clear();
    lcd.print("initialization");
    lcd.setCursor(0,1);
    lcd.print("failed!");
    return;
  }
   lcd.clear();
   lcd.print("initialization done");
   delay(2000); //delay or else the message will not be displayed
   lcd.clear();
   lcd.print("listing 4 files");
   delay(2000); //delay or else the message will not be displayed
   root = SD.open("/");
   lcd.clear();
   printDirectory(root, 0);
}

void printDirectory(File dir, int numTabs) {
  int row=0;
   while(true) {
     if(row>3) return;
     lcd.setCursor(0,row);
     File entry =  dir.openNextFile();
     if (! entry) {// no more files
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       lcd.print(' ');
     }
     lcd.print(entry.name());
     if (entry.isDirectory()) {
       lcd.print("/");
       printDirectory(entry, numTabs+1);
       row++;
     } else {
       // files have sizes, directories do not
       lcd.print("  ");
       lcd.print(entry.size(), DEC);
       row++;
     }
     entry.close();
   }

}

This sketch, and the adapted Kicad schematic are all on the Think3dPrint3d github.

Next...

I will test more LCD screens and hopefully will be able to get the next batch of PanelOnes compatible with both 3.3V and 5V.

The big job will be to port and adapt the Marlin menu system to RepRap Firmware. If anyone wants to assist with this project then drop me a line and I may be able to help with some hardware (duet board + LCD screen).

Tuesday, 12 March 2013

Panelolu2 for Melzi

Panelolu2 LCD display and control solution working with Melzi Electronics.

The previous post outlined the functionality of the Panelolu2 - broadly similar to the Panelolu but with a reduced pin count allowing it to interface with more controllers. In order to simplify adding the Panelolu2 to your printer the design includes adapter boards and the second adapter board we have produced is for the Melzi controller:



This runs Marlin firmware which has been specifically adapted to support an I2C controller, a number of people are working to incorporate the I2C LCD control code into the standard Marlin build.

The adapter board schematic is below:


The adapter boards will be supplied fully assembled by default:




As the picture above shows they can do more than just provide an interface between the Melzi electronics and the Panelolu2. There are two FETs mounted which can be used to switch a 12V supply, useful for adding additional fans to you printer. Unlike the Sanguinololu the Melzi does not provide 12V on the expansion header so an additional 12V input is needed (The easiest way to do this is to use a short lead to provide the 12V supply from the 12V input to the Melzi board).

The expansion header allows access to the I2C pins so additional devices can be added to the bus, along with the two pins connected to the FETs and the click encoder pins. In normal use the click encoder pins are used for the encoder and cannot be used for anything else. However, as explained in the previous post, running the encoder over I2C may be supported in software in the future which would free these pins up to be used elsewhere. The board has solder jumpers to select between these two modes of operation, with the default being the normal, directly connected mode.




Using the additional FETs

The additional FETs are connected to pins A3 and A4 which map as arduino pin numbers 27 and 28. Pin 27 is the LED pin - setting that pin high turns on the FET and the LED at the same time.

Currently these FETS are not directly controlled in firmware (there is no menu command to turn them on and off) but that is in the pipeline. In the meantime they can be controlled in GCODE by using the M42 command (for example in your startup and shutdown code). Once I get a chance to wire it in I plan to use this in the end of print gcode to drive a fan that will cool the heated bed rapidly (originally Nophead's idea and incorporated into the Mendel90 design)

M42 S255 P27 ;turn on the fan on Transistor 2
G4 S240 ; wait for 4 minutes
M42 S0 P27 ;turn off the fan on Transistor 2

The other FET could be used to drive a fan to cool the stepper drivers or not used at all and the pin used on the expansion header on the adapter board for some other function.

SD Card

The firmware with the P2 changes is setup to use the P2 SD card slot rather than the built in SD card slot on the Melzi. The difference is in the definition of the SDSS pin in pins.h in Marlin. The specific line in pins.h is:

#define SDSS 30 //to use the SD card reader on the Panelolu2 rather than the melzi board

Comment this line out to us the SD card on the melzi board instead. It is not currently possible to use both and select between them after the firmware is compiled.

Summary

Update, added this section to summarise the process of getting the Panelolu2 working on a Melzi where the Melzi was previously running a "non standard" version of Marlin such as Nophead's version for M90 or RepRapPro's version of Huxley/Mendel. Please note that if you are using RepRapPro's Multicolour Mendel you need to use their custom variation of Marlin to control the multiple extruders and at this time the Panelolu2 is not compatible with this setup.


  1. If you are not already using it get the standard version of Arduino-0023 from the Arduino website, note that the T3P3 version of Marlin has not been tested with Arduino 1.0 or higher.
  2. Update the avrdude.conf file in the standard Arduino-0023 to include a definition of the atmega 1284p, I have used this one for a year now. Be sure to put it in arduino-0023\hardware\tools\avr\etc\ and rename or overwrite the old one. More detail in my first blog post
  3. Get T3P3 Marlin from github.
  4. Add the "Marlin\ArduinoAddons\Arduino_0.xx\Sanguino" directory to "arduino-0023\Hardware\" directory. This provides the Sanguino extensions required for Sanguinol and Melzi.
  5. Get LiquidTWI2 as mentioned in my Panelolu2 blog post, note that configuration changes are no longer required in the latest version of LiquidTWI2.
  6. Modify the configuration.h of the Marlin to fit your printer setup (setting like controller board, axis dimensions, thermistors, etc). Its best to copy these from the configuration.h of your custom firmware. Update: This blog post should help.
  7. Confirm Marlin compiles and uploads with //#define PANELOLU2 still commented out in configuration.h.
  8. Then uncomment #define PANELOLU2 , along with #define EEPROM_SETTINGS and #define EEPROM_CHITCHAT and confirm it compiles and uploads. Note that with the #define PANELOLU2 uncommented, you must have the Panelolu2 connected or Marlin will hang and not finish initialising.
  9. Check the printer operation and calibration to ensure you have edited the Marlin configuration.h properly.


Availability

Update: Now available on our webstore as well as eMakershop and eBay

Friday, 15 February 2013

Panelolu2

Panelolu2 - An I2C control solution for Sanguinololu, Melzi and more

The original Panelolu was designed to provide a simple user interface for a 3d printer controlled by a Sanguinololu and similar electronics - enabled by the Ultipanel code within the Marlin firmware. By connecting to the right pinouts it also works with Printrboard and RAMPS.

I have developed a new version which uses an I2C port expander to drive the LCD screen and adds a piezo buzzer and indication LEDs. This version uses less pins, making it compatible with the Melzi electronics and even leaves enough spare pins to drive a couple more outputs (such as an additional extractor fan and stepper driver cooling fan).


Panelolu2 Front View
  
In the photo above the grid covers the piezo buzzer and the H,E and F LEDs indicate that the Heated bed, Extruder and Fan (or second extruder) are on. It would be relatively simple to change the firmware to have these LEDs turn on for another reason. The R for reset and the encoder wheel are the same as in the original Panelolu although I have made the encoder wheel about 1/3 smaller to fit better. 

Circuit board

The Panelolu2 design simplifies the assembly by mounting all components on one circuit board that can be soldered directly to an LCD screen. The standard way to connect it to the screen is with a single row of 2.54mm headers as shown below. This row of headers could be replaced by wires (ribbon cable would be best) - enabling a variey of case designs, such as Printbit's Panelolu Box for Mendel Max.


This simplification also extends to the wiring which is now a 2x6 IDC plug on both ends of a ribbon cable. The circuit uses a combination of through hole and surface mount components; the other side of the prototype circuit board is shown below. The brightness and contrast pots are now on the back of the board and can be adjusted through the rear of the case.



I have tidied up the Schematic: the components are the MCP23017 port expander, the SD card circuitry, buzzer, click encoder and LEDS.

 

Of course the whole project is Open Source Hardware and the eagle files are available on github.

Case design

As mentioned above, the circuit board and LCD allow for multiple case designs. I have made a simple case with a back leg allowing the Panelolu2 to sit on the bench alongside the printer.
 
Panelolu2 Side View 

The case design is all done in OpenSCAD with both .scad and .stl versions of the files, available on Thingiverse. One of the great things I have found about Thingiverse is it allows you to embed the Thingiviews of the STL files, so here are the front and back case views:

Front
 
 
Back
 



The OpenSCAD file also allows the back leg to be generated to support the case at your chosen angle. For the rotary encoder I adapted Miserybot's "Spinner Knob" design to make it about 1/3 smaller and a lot thinner - the .stl is on Thingiverse and I will upload the OpenSCAD code once it is cleaned up.


Adapter Boards

One of the aims of the Panelolu2 was to reduce the complexity involved in wiring it up. I have designed adapter boards to allow compatibility of the Panelolu2 with various electronics. The picture below shows the adapter board connected to a Sanguinololu.



Update added the Sanguinololu and Melzi adapter schematics:



As can be seen from the schematic the two mosfets for driving additional light loads such as fans are on the PWM and A3 pins on the Sanguinololu. These pins can be accessed as Arduino digital pins 4 for the pin labelled PWM and 28 for the pin labelled A3. In Marlin firmware to turn on the fan connected to Transistor 1:

M42 S255 P4

And transistor 2

M42 S255 P28

In overview the picture below shows the inputs and outputs from the prototype Melzi adapter board.


The Schematic for the Melzi adapter board is:



The same logic as described the solder jumper operations on the Sanguinololu adapter board applies to the Melzi board. For the two additional outputs they are on pin A4 and A3 which are digital pins 27 and 28 respectively.In Marlin firmware to turn on the fan connected to Transistor 1:

M42 S255 P28

And transistor 2

M42 S255 P27

For basic operation the ISP and expansion header plug into the Melzi and the Panelolu plugs into its 2x6 connector. If desired FETs can be mounted to switch a 12V supply, for example to drive external fans.

As an alternative to the adapter board, standard female housings with crimp connectors could be used. I intend to design boards for Printrboard and RAMPS in the near future.
(update: done, see this blog post)

I2C encoder option 

Instead of linking the encoder and switch directly to pins on the Sanguinololu, Melzi or other electronics, the hardware has the option to run the encoder and switch over I2C. This would free up a couple more pins but the option is not yet supported by firmware. The Panelolu2 circuit board and adapter boards have solder jumpers, shown below on the back of the Melzi adapter board



Currently the firmware does not support routing the encoder signals over I2C so by default these jumpers will be set for normal operation.


Firmware 


The Panelolu2 only runs on Marlin firmware at the moment. Excellent work was done by Daid in the Marlin code to split the LCD screen hardware from the user interface. This made it straightforward to implement the Panelolu2 code. As mentioned in previous posts LiquidTWI2 by Lincomatic is required; download it from github, rename the directory from "LiquidTWI2-master" to "LiquidTWI2 and put it in the

arduno-0023/libraries/

sub-folder.

UPDATE: - This step is no longer required in the latest version of LiquidTWI2 (1.2.4) the library will work out the box with no configuration changes required.

By default the Panelolu2 is disabled in LiquidTWI2, after saving the directory, edit LiquidTWI2.h to remove the comments on line 10:

 //  #define PANELOLU2 //only possible....


To

    #define PANELOLU2 //only possible....
 

Continue following the instructions from here:

Then download the T3P3 fork of Marlin, make the changes you need to configuration.h to suit your printer and ensure :

#define EEPROM_SETTINGS
and

#define PANELOLU2

are uncommented within configuration.h then upload as normal. The compiled Marlin is ~100k, a very similar size to Marlin compiled for the original Panelolu, so the electronics board will need enough space (a 1284P is fine, a 644P does not have enough space).


Summary

Update, added this section to summarise the process of getting the Panelolu2 working Sanguinololu.


  1. If you are not already using it get the standard version of Arduino-0023 from the Arduino website, note that the T3P3 version of Marlin has not been tested with Arduino 1.0 or higher.
  2. If you are not already using a Sanguinololu with 1284P then update the avrdude.conf file in the standard Arduino-0023 to include a definition of the atmega 1284p, I have used this one for a year now. Be sure to put it in arduino-0023\hardware\tools\avr\etc\ and rename or overwrite the old one. More detail in my first blog post.
  3. Get T3P3 Marlin from github.
  4. If you are not already using a Sanguinololu with 1284P add the "Marlin\ArduinoAddons\Arduino_0.xx\Sanguino" directory to "arduino-0023\Hardware\" directory. This provides the Sanguino extensions required for Sanguinol and Melzi.
  5. Get LiquidTWI2 as mentioned above, note that configuration changes are no longer required in the latest version of LiquidTWI2.
  6. Modify the configuration.h of the Marlin to fit your printer setup (setting like controller board, axis dimensions, thermistors, etc). Its best to copy these from the configuration.h of your existing firmware. Update: This blog post should help.
  7. Confirm Marlin compiles and uploads with //#define PANELOLU2 still commented out in configuration.h.
  8. Then uncomment #define PANELOLU2 , along with #define EEPROM_SETTINGS and #define EEPROM_CHITCHAT and confirm it compiles and uploads. Note that with the #define PANELOLU2 uncommented, you must have the Panelolu2 connected or Marlin will hang and not finish initialising.
  9. Check the printer operation and calibration to ensure you have edited the Marlin configuration.h properly.

Availability

As always the hardware is open source so the design files are available on Github: https://github.com/T3P3/Panelolu2.

Update: Now available on our webstore and on eMakershop and eBay 

Thursday, 29 November 2012

Panelolu on RAMPS and PrintrBoard issues


Panelolu on RAMPS


Update: The Panelolu2 has replaced the Panelolu. It is much quicker to install, has adapter boards to no messing with cables and uses less pins. The blog post with the information is here, it is available to buy in our webshop.

The original idea for the Panelolu was based on the PanelMax which works with RAMPS. What I had not got around to doing was determining the changes needed to the pin mapping to cable for the Panelolu to work on RAMPS. Thankfully Ian Stratford has done the hard work and worked it all out.

Update: Ian has also made the Panelolu page on the reprap wiki - thanks!

The tables below refer to the RAMPS pin outs from the reprap wiki - the picture is below



The tables below cover the differences between the RAMPS setup and the original instructions: Panelolu on Sanguinololu.

Ribbon Cable number
Function
Pin Sanguinololu
Pin RAMPS
1
GND
GND
NA
2
12V
12V
NA
3
LCD 1 (VSS - Ground)
LCD 5 (RW - Read/Write)
LCD 16 (K - Backlight Anode-)
Breadboard GND for encoder, switch, contrast, reset.
GND
GND (AUX-4)
4
LCD 2 (VDD +3.3 to +5v)
5V on breadboard, for brightness
5V
5V (AUX-4)
5
LCD 14 (DB7 - data bit)
A4
D29
6
LCD 4 (RS - register select)
PWM D12
D16
7
LCD 13 (DB6 - data bit)
A3
D27
8
Encoder1
TX1 D11
D35
9
LCD 12 (DB5 - data bit)
A2
D25
10
Encoder2
RX1 D10
D37
11
LCD 11 (DB4 - data bit)
A1
D23
12
LCD 6 (E - clock)
SDA D17
D17
13
SD (CS pin)
A0
D53
14
(via SDSL plug, NC) Encoder click
SCL D16
D31            
15
(via SDSL plug, NC)


16
(via SDSL plug, NC)


17
SD Ground
GND
GND
18
(via SDSL plug, NC) Reset
RST
No RST pin?
19
SD (DI pin)
MOSI
MOSI D51
20
SD (SCK pin)
SCK
SCK D52
21
SD 5V
5V
5V
22
SD (DO pin)
MISO
MISO D50
23
NA
NA

24
NA
NA





Other
LCD 3 (VO – contrast adjuster) to C on breadboard


Other
LCD 15 (A – Backlight Anode+) to B on breadboard (brightness)



RAMPS AUX-4
Ribbon Cable number
Function
Pin Sanguinololu
Pin RAMPS
6
LCD 4 RS (register select)
PWM D12
D16
12
LCD 6 E (clock)
SDA D17
D17
11
LCD 11 DB4
A1
D23
9
LCD 12 DB5
A2
D25
7
LCD 13 DB6
A3
D27
5
LCD 14 DB7
A4
D29
14
SD, encoder click
SCL D16
D31      

(Piezo Buzzer +)

D33
8
Encoder1
TX1 D11
D35
10
Encoder2
RX1 D10
D37
3
Ground
GND
GND
4
5V
5V
5V

RAMPS AUX-3 / SPI
Ribbon Cable number
Function
Pin Sanguinololu
Pin RAMPS
17
SD Ground
GND
GND

NC

NC
20
SD (SCK pin)
SCK
SCK D52
13
SD (CS pin)
A0
D53
22
SD (DO pin)
MISO
MISO D50
19
SD (DI pin)
MOSI
MOSI D51
21
SD 5V
5V
5V

NC

D49

To quote Ian
"I have managed to connect up the Panelolu kit to my RAMPS board with great success! Everything works except the reset button, as there is no reset pin on RAMPS. I added a piezo electric buzzer as well (from an old PC). Cabling is pretty straightforward, I just needed to trace the connection to the right pin. I built the Panelolu kit as per the Sanguinololu instructions, then used a couple of different sources to work out the correct pins on the RAMPS board. Then all I had to do was uncomment the #define ULTIPANEL line in Marlin. I did check the pins.h file, but it's already all in there for RAMPS. Worked first time!!"
Its now on my todo list to make up a cable to connect to RAMPS, something I intend to use on a dual extruder M90.

Printrboard issues

One of our customers, Bernardo, highlighted an issue with the Printrboard design: the Y-endstop is on the SS pin. Bernardo found the solution on Colin Bradburne's blog which I wont repeat here but if you are intending on using an SD card with Printrboard it is well worth reading his blog.