Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Monochron <-> Arduino?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Monochron <-> Arduino?

by wbp on Sat Jul 28, 2012 5:10 pm

I will have to see if I can find all the bits. The Arduino "project" is only part of it, I also hacked the graphics library. I'll try to put it all together and post it here...

wbp
 
Posts: 260
Joined: Mon Mar 07, 2011 1:18 pm

Re: Monochron <-> Arduino?

by edc1591 on Wed Aug 01, 2012 8:39 am

Great, thanks! Also, were you able to get the DHT11 to work on it? I'm trying to get the DHT22 to work with the monochron and Arduino IDE and it doesn't seem to work. I suspect the problem lies with the custom hardware files in the Arduino IDE for the monochron, that's why I'd like to see yours.

EDIT: I managed to get it working using this DHT library (http://arduino.cc/playground/Main/DHTLib). However, I'd still like to see your monochron firmware if you can find it.
edc1591
 
Posts: 40
Joined: Sat Jul 14, 2012 11:12 am
Location: New York, NY

Re: Monochron <-> Arduino?

by ruthsarian on Sat Dec 19, 2015 12:43 am

I've had an unassembled Monochron kit in my closet for a couple years now and finally got up the courage last week to overcome my poor soldering skills to try and assemble it. It worked and now I want to write new programs for it. And that is how I came across this thread. I've got Monochron working with Arduino 1.6.7 and I thought I would share what it took to get it started just in case someone else has one in their closet waiting assembly.

First, thank you Stephanie and wbp who provided all the information in this thread. All I did was find where I needed to apply their mods to get this working.

For the graphics library I am using openGLCD which is where the developer of the original ks0108 library has continued their work. Download the latest version (I'm using v1.0rc2) and install it through the IDE (Sketch -> Include Library -> Add .ZIP Library).

Now some changes need to be made to both the openGLCD library and the Arduino IDE's libraries to get them using the correct PINs to control the LCD.

Arduino IDE Changes

You'll need to create a new board definition for the Monochron. Here's my definition, which you can add to the end of the boards.txt file located in <IDE Install Home>/hardware/arduino/avr/
Code: Select all | TOGGLE FULL SIZE
##############################################################
monochron.name=MonoChron Clock w/ ATmega328p
monochron.upload.protocol=arduino
monochron.upload.maximum_size=30720
monochron.upload.speed=57600
monochron.upload.tool=avrdude
monochron.bootloader.tool=avrdude
monochron.bootloader.low_fuses=0xE2
monochron.bootloader.high_fuses=0xD7
monochron.bootloader.extended_fuses=0x05
monochron.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
monochron.bootloader.unlock_bits=0x3F
monochron.bootloader.lock_bits=0x0F
monochron.build.mcu=atmega328p
monochron.build.f_cpu=8000000L
monochron.build.core=arduino
monochron.build.variant=standard
monochron.build.board=AVR_MONOCHRON

Next, you need to let the IDE know there are two more PINs than standard by editing pins_arduino.h in <IDE home>/hardware/arduino/avr/variants/standard/. digital_pin_to_port_PGM and digital_pin_to_bit_mask_PGM need to be modified to include two extra pins. You'll want to modify the block of code that begins on (or near) line 132. That block of code, after modification, should look like this:
Code: Select all | TOGGLE FULL SIZE
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
   PD, /* 0 */
   PD,
   PD,
   PD,
   PD,
   PD,
   PD,
   PD,
   PB, /* 8 */
   PB,
   PB,
   PB,
   PB,
   PB,
   PC, /* 14 */
   PC,
   PC,
   PC,
   PC,
   PC,
   PB, /* 20 -- added this line to include the xtal lines */
   PB, /* 21 -- added this line to include the xtal lines */
};

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
   _BV(0), /* 0, port D */
   _BV(1),
   _BV(2),
   _BV(3),
   _BV(4),
   _BV(5),
   _BV(6),
   _BV(7),
   _BV(0), /* 8, port B */
   _BV(1),
   _BV(2),
   _BV(3),
   _BV(4),
   _BV(5),
   _BV(0), /* 14, port C */
   _BV(1),
   _BV(2),
   _BV(3),
   _BV(4),
   _BV(5),
   _BV(6), /* 20, port B xtal -- added this line to include the xtal lines */
   _BV(7), /* 21, port B xtal -- added this line to include the xtal lines */
};

openGLCD Changes

In the directory <openGLCD home>/config/ks0108 create a copy of the file ManualConfig_ks0108_Panel.h and rename it ManualConfig_ks0108_Monochron.h. Next, open the file up and make the following changes:
  • line 54: change the value of glcdPinCSEL1 from A0 to 14
  • line 55: change the value of glcdPinCSEL2 from A1 to 2
  • line 67: change the value of glcdPinRW from A2 to 13
  • line 68: change the value of glcdPinDI from A3 to 21
  • line 69: change the value of glcdPinEN from A4 to 12
  • line 74: Uncomment glcdPinBL line and change its value from XX to 3
The updated block of code should now look like this:
Code: Select all | TOGGLE FULL SIZE
/* Arduino pins used for control
 * default assignment uses the first five analog pins
 */
#define glcdPinCSEL1        14
#define glcdPinCSEL2        2
// uncomment the following if more than two chip select pins are needed
//#define glcdPinCSEL3        3   // third chip select line on pin 3 if needed
//#define glcdPinCSEL4        2   // fourth chip select if needed

// For using multiple displays as a larger virtual display
//#define glcdPinCSEL5        ?   // 5th chip select if needed
//#define glcdPinCSEL6        ?   // 6th chip select if needed
//#define glcdPinCSEL7        ?   // 7th chip select if needed
//#define glcdPinCSEL8        ?   // 8th chip select if needed
//#define glcdPinCSEL9        ?   // 9th chip select if needed

#define glcdPinRW            13
#define glcdPinDI            21
#define glcdPinEN            12
// Reset - uncomment the next line if glcd module reset is connected to an output pin
//#define glcdPinRES            A5    // optional s/w Reset control

// backlight control pin
#define glcdPinBL   3 // optional backlight control pin controls BL circuit
Now you'll need to tell openGLCD to use this new configuration. To do that edit the file openGLCD_Config.h located in the openGLCD home directory. Comment out line 81, it will be the only #define GLCDCFG_GLCDCONFIG line that is not commented out. Now scroll down to the "Manual config files" section and add the following lines to the end of that section (around line 132)
Code: Select all | TOGGLE FULL SIZE
// configuration for Monochron
#define GLCDCFG_GLCDCONFIG "config/ks0108/ManualConfig_ks0108_Monochron.h"
Lastly, openGLCD also needs to know about the two extra pins that the IDE was modified to recognize. Open the file glcd_arduino_io.h in the directory <openGLCD home>/include and modify digitalPinToPortReg and digitalPinToBit (beginning around line 128) to include the two pins. The modified version of this block of code will look like this:
Code: Select all | TOGGLE FULL SIZE
#define digitalPinToPortReg(P) \
   (\
   (P) == 0 ? &PORTD : \
   (P) == 1 ? &PORTD : \
   (P) == 2 ? &PORTD : \
   (P) == 3 ? &PORTD : \
   (P) == 4 ? &PORTD : \
   (P) == 5 ? &PORTD : \
   (P) == 6 ? &PORTD : \
   (P) == 7 ? &PORTD : \
   (P) == 8 ? &PORTB : \
   (P) == 9 ? &PORTB : \
   (P) == 10 ? &PORTB : \
   (P) == 11 ? &PORTB : \
   (P) == 12 ? &PORTB : \
   (P) == 13 ? &PORTB : \
   (P) == 14 ? &PORTC : \
   (P) == 15 ? &PORTC : \
   (P) == 16 ? &PORTC : \
   (P) == 17 ? &PORTC : \
   (P) == 18 ? &PORTC : \
   (P) == 19 ? &PORTC : \
   (P) == 20 ? &PORTB : \
   (P) == 21 ? &PORTB : \
   &PORTC) // dummy entry (should never happen)

#define digitalPinToBit(P) \
   (\
   (P) == 0 ? 0 : \
   (P) == 1 ? 1 : \
   (P) == 2 ? 2 : \
   (P) == 3 ? 3 : \
   (P) == 4 ? 4 : \
   (P) == 5 ? 5 : \
   (P) == 6 ? 6 : \
   (P) == 7 ? 7 : \
   (P) == 8 ? 0 : \
   (P) == 9 ? 1 : \
   (P) == 10 ? 2 : \
   (P) == 11 ? 3 : \
   (P) == 12 ? 4 : \
   (P) == 13 ? 5 : \
   (P) == 14 ? 0 : \
   (P) == 15 ? 1 : \
   (P) == 16 ? 2 : \
   (P) == 17 ? 3 : \
   (P) == 18 ? 4 : \
   (P) == 19 ? 5 : \
   (P) == 20 ? 6 : \
   (P) == 21 ? 7 : \
   0) // dummy entry (should never happen)
It's important to note those last two entries in digitalPinToPortReg should say PORTB and not PORTC.

And that's it! Time to test it out.

Load up the openGLCD HelloWorld example (Files -> Examples -> openGLCD -> HelloWorld).
Make sure the Monochron board you added is selected (Tools -> Board -> MonoChron Clock w/ ATmega328p)
And if you're using the FTDI cable to program your Monochron, select the "Arduino as ISP" programmer (Tools -> Programmer -> "Arduino as ISP")
Connect your Monochron (and make sure the right COM port is selected under Tools -> Port)
Click the "Upload" button and the IDE will compile and upload the HelloWorld project. If all goes well your Monochron should display the text "hello, world!" and a number beneath it that increments every second.

ruthsarian
 
Posts: 1
Joined: Fri Dec 18, 2015 11:57 pm

Please be positive and constructive with your questions and comments.