Thursday, February 24, 2011

Uploading sketches to Wise Clock 3/4

Updated April 7, 2013 - added details (sanguino section in boards.txt etc).
Although this post was written for Arduino 21, it applies almost identically to Arduino 1.0 and later.
I say "almost" because:
- WProgram.h was replaced by Arduino.h
- the original sanguino files may not be maintained publicly anymore. Instead of copying them from sanguino.cc, as suggested originally, you can download my updated (for Arduino 1.0+) version from here.


Updated March 6, 2011 - Added screenshot for WiseClock3 folder (after unziping).

Sooner or later, if you have Wise Clock 3 or 4, you may want to upgrade the software.
This process requires the following prerequisites:
  1. the Sanguino-related files need to be installed (since Wise Clock 3/4 is compatible with Sanguino);
  2. an FTDI cable/breakout is required to upload the sketch to the board.

To install the Sanguino files, you may follow the instructions found here. Basically, you need to do two things:
  • Firstly, add the definition of the Sanguino board to the file arduino21/hardware/arduino/boards.txt;
This "Sanguino" section should look like this:

sanguino.name=Sanguino
sanguino.upload.protocol=stk500
sanguino.upload.maximum_size=63488
sanguino.upload.speed=38400
sanguino.bootloader.low_fuses=0xFF
sanguino.bootloader.high_fuses=0xDC
sanguino.bootloader.extended_fuses=0xFD
sanguino.bootloader.path=atmega644p
sanguino.bootloader.file=ATmegaBOOT_644P.hex
sanguino.bootloader.unlock_bits=0x3F
sanguino.bootloader.lock_bits=0x0F
sanguino.build.mcu=atmega644p
sanguino.build.f_cpu=16000000L
sanguino.build.core=sanguino
sanguino.verbose=false

Pay attention to the upload speed (38400), which is "burned" in the bootloader and essentially important for communication with the board (sketch upload, serial monitoring). Also pay attention to the second last value, which indicates the folder where core files are found. This parameter MUST not be "arduino", but "sanguino". Thanks to Dave, who found this potential issue. Even though compilation and uploading were successful, the sketch failed to run as expected. This was because the core files used at build time were not those  for ATmega644/ATmega1284 (as used in sanguino).

If your processor is ATmega1284, the "Sanguino" section in boards.txt should look like this:

atmega1284.name=Sanguino W/ ATmega1284p 16mhz
atmega1284.upload.protocol=stk500v1
atmega1284.upload.maximum_size=129024
atmega1284.upload.speed=57600
atmega1284.bootloader.low_fuses=0xFF
atmega1284.bootloader.high_fuses=0x98
atmega1284.bootloader.extended_fuses=0xFD
atmega1284.bootloader.path=atmega
atmega1284.bootloader.file=atmega1284p_16MHz.hex
atmega1284.bootloader.unlock_bits=0x3F
atmega1284.bootloader.lock_bits=0x0F
atmega1284.build.mcu=atmega1284p
atmega1284.build.f_cpu=16000000L
atmega1284.build.core=sanguino

Note that for ATmega1284 the upload speed is 57600. Also note that the core folder (last parameter in the list above) is still "sanguino".

  • Secondly, create the folder "sanguino" and copy the Sanguino files, as shown in the screenshot below.













After these two steps are completed, you should see "Sanguino" listed in the menu "Tools/Board" of Arduino IDE 21 (used as an example here).





















To upload the sketch, you will need to connect the board to the PC/Mac with an FTDI cable/breakout. The USB end of this cable gets plugged into the PC/Mac, the FTDI end gets connected to the Wise Clock 3/4 board as shown in the photo below.















With both the software and hardware in place, the upgrade will consist in the following steps:
  • download the latest software on the PC;
  • launch Arduino IDE and load the sketch;
  • compile, after chosing "Sanguino" as the target board;
  • upload to the Wise Clock 3/4 board.
Unziping the WiseClock3/4 source code (found here) should result in a directory structure as shown in the screenshot below.













If you get compilation errors related to "tone.cpp" file, like the following,

...\ArduinoIDE\libraries\WiseClock3\Sound.cpp: In function 'void soundAlarm()':
...\ArduinoIDE\libraries\WiseClock3\Sound.cpp:60: error: 'tone' was not declared in this scope
...\ArduinoIDE\libraries\WiseClock3\Sound.cpp: In function 'void beep()':
...\ArduinoIDE\libraries\WiseClock3\Sound.cpp:75: error: 'tone' was not declared in this scope

make sure the file Tone.cpp is present in the sanguino folder, as shown in the next screenshot.












(April 7, 2013: The following info is obsolete now. File WProgram.h was replaced by Arduino.h.)

Also, make sure that WProgram.h (in the sanguino folder) contains the line

void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);



7 comments:

  1. Hi,

    I am having problem compiling the Wise Clock 3 code. The installation instructions for Sanguino specified in the readme files are different than above - now it seems you only need to copy the Sanguino folder into hardware folder of the IDE. You also need to modify the WProgram.h. However, after that I am stumped. The supplied pde file cannot be used unless it is copied into the root folder where the other C and H files are (is there a reason it's not there in the first place?). And once it's there, the sketch still fails to compile, with the error:

    core.a (main.cpp.o): In function 'main':
    C:\Program Files (x86)\arduino-0023\hardware\Sanguino\cores\arduino/main.cpp:7: undefined reference to 'setup'
    C:\Program Files (x86)\arduino-0023\hardware\Sanguino\cores\arduino/main.cpp:7: undefined reference to 'loop'

    Any idea how to fix this?

    ReplyDelete
  2. Andrew,
    I remember I heard of a similar issue some time ago, but I don't remember exactly how I fixed it.
    The first thing coming to mind is to copy the file "main.cpp" from the folder .../cores/arduino to folder cores/sanguino.
    Please let me know if that works.
    Otherwise, we can take it "offline", that is, send me an email. We'll fix it.

    ReplyDelete
  3. That looks like a linking error. The missing functions are, however, defined in the sketch. I created a brand new sketch from scratch and then painstakingly, manually added each file from the WiseClock3 folder. Manually copying files does not work and there is no multi-add feature in Arduino IDE as I couldn't select more than one file at a time. Then I copied the code (which includes loop() and setup()) from WiseClock3.pde to the new sketch. The compilation and linking was successful after that. I don't know why it didn't work to begin with using supplied WiseClock3.pde. Perhaps because I copied it from examples folder into the base folder where other files are (but without that step it doesn't find all those other files and fails anyhow)?

    ReplyDelete
  4. Hi
    I have tried the code for wiseclock 4 in both arduino 023 and 1.01 and the same error code keeps coming up, when I verify the code it stop at setupSpeaker(); and shows the following errors
    WiseClock4.ino:50:20: error: HT1632.h: no such file or directory
    WiseClock4.ino:50:20: error: SDuFAT.h: no such file or directory
    WiseClock4.ino:50:19: error: Sound.h: no such file or directory
    WiseClock4.ino:50:21: error: Buttons.h: no such file or directory
    WiseClock4.ino:50:24: error: AlarmClock.h: no such file or directory
    WiseClock4.ino:50:24: error: WiseClock4.h: no such file or directory
    WiseClock4.ino: In function 'void setup()':
    WiseClock4:69 error: 'setupSpeaker' was not declared in this scope
    WiseClock4:71 error: 'setupButtons' was not declared in this scope

    WiseClock4:73 error: 'beep' was not declared in this scope
    WiseClock4:76 error: 'wiseClock' was not declared in this scope
    WiseClock4:78 error: 'alarmClock' was not declared in this scope
    WiseClock4:81 error: 'ht1632_setup' was not declared in this scope
    WiseClock4.ino: In function 'void loop()':
    WiseClock4:94: error: 'checkButtons' was not declared in this scope
    WiseClock4:96: error: 'alarmClock' was not declared in this scope
    WiseClock4:100: error: 'wiseClock' was not declared in this scope

    any idea what I am doing wrong ?

    ReplyDelete
    Replies
    1. Arduino IDE 1.01 should work.
      Did your unzipping create the same directory structure as showed in the 3rd screenshot above? Do you have all those files (cpp and h) in the WiseClock directory?
      The .ino file should be called TheClock.ino (rather than WiseClock4.ino), if you picked up the latest version:
      https://code.google.com/p/wiseclock2/downloads/detail?name=WiseClock_130923.zip&can=2&q=#makechanges

      You also have to select "Sanguino" as your board.

      Delete
    2. BTW, the processor comes programmed with the latest version, so you don't have to upload any sketch, unless you want to modify or make your own version.

      Delete
    3. Thanks Florin
      Have sorted the problem out, did have the files in the wrong directory.
      didn't know it came programmed good to know.
      Thanks again
      Andy

      Delete