Sanguino - blink doesn't work

I found it actually blinks when plugged into D5

By "D5" do you mean "port D bit 5" (I think Atmel uses the label "PD5") or do you mean "Arduino digital pin 5"?

From the diagram below, which was in pins_arduino.c supplied in the Sanguino downloads, it works in D5 (PB5, pin 6) but not in D13 (PD5, pin 19). The working pin is processor pin 6, which a visual inspection seems to indicate that is directly connected to the 6th edge connector pin (ie. pin 1 is D0, pin 2 is D1, etc.). See schematic attached.

// ATMEL ATMEGA644P / SANGUINO
//
//                   +---\/---+
//  INT0 (D 0) PB0  1|        |40  PA0 (AI 0 / D31)
//  INT1 (D 1) PB1  2|        |39  PA1 (AI 1 / D30)
//  INT2 (D 2) PB2  3|        |38  PA2 (AI 2 / D29)
//   PWM (D 3) PB3  4|        |37  PA3 (AI 3 / D28)
//   PWM (D 4) PB4  5|        |36  PA4 (AI 4 / D27)
//  MOSI (D 5) PB5  6|        |35  PA5 (AI 5 / D26)
//  MISO (D 6) PB6  7|        |34  PA6 (AI 6 / D25)
//   SCK (D 7) PB7  8|        |33  PA7 (AI 7 / D24)
//             RST  9|        |32  AREF
//             VCC 10|        |31  GND 
//             GND 11|        |30  AVCC
//           XTAL2 12|        |29  PC7 (D 23)
//           XTAL1 13|        |28  PC6 (D 22)
//  RX0 (D 8)  PD0 14|        |27  PC5 (D 21) TDI
//  TX0 (D 9)  PD1 15|        |26  PC4 (D 20) TDO
//  RX1 (D 10) PD2 16|        |25  PC3 (D 19) TMS
//  TX1 (D 11) PD3 17|        |24  PC2 (D 18) TCK
//  PWM (D 12) PD4 18|        |23  PC1 (D 17) SDA
//  PWM (D 13) PD5 19|        |22  PC0 (D 16) SCL
//  PWM (D 14) PD6 20|        |21  PD7 (D 15) PWM
//                   +--------+

In the image below, the pin circled in red, and labelled 5 on the board (really processor pin 6) works, the pin circled in green, and labelled 13 does not work.

Sanguino_Picture.png

Another view of the pinouts:

Sanguino_pinouts.jpg

"pins_arduino.c" looks fine. The DDR, PIN, and PORT addresses are all below 256. The slots for pin 13 look fine. Huh. Looks like we have a mystery on our hands.

First, a quick sanity check. Do you have the Sanguino selected on the Tools / Board menu?

Try this for blinking pin 13...

void setup( void )
{
  DDRD |= _BV(5);
}

void loop( void )
{
  PORTD |=   _BV(5);
  delay( 1000 );
  PORTD &= ~ _BV(5);
  delay( 1000 );
}

This is a note to myself in case the test above works. Just ignore it...

uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out;
out = portOutputRegister(port);

#define PD 4

digital_pin_to_port_PGM
PD

digital_pin_to_bit_mask_PGM
_BV(5)

I admit I didn't do the complete installation

Exactly which parts did you do?
PB5 (D5 on Sanguino) would be D13 on a regular ATmega328-based Arduino, so it looks like you don't have the Sanguino pin definitions installed correctly.

Yes. :wink:

That blinks the correct pin. I don't really doubt the pin can be made to blink, and I thank you for showing me in a couple of lines of code how to do it, but I wonder if there isn't some problem with the Sanguino with reference to the defines in the standard libraries.

Now I think a perfectly acceptable response would be "ah, but we don't support the Sanguino - work it out yourself" and I would sigh and rewrite various low-level routines.

I suppose what I am asking is, has anyone done this already, to save me the time in doing it?

westfw:
Exactly which parts did you do?
PB5 (D5 on Sanguino) would be D13 on a regular ATmega328-based Arduino, so it looks like you don't have the Sanguino pin definitions installed correctly.

I appended the contents of boards.txt into my main boards.txt file, as instructed, so it would add Sanguino to my "boards" menu, and program it correctly.

But I baulked at replacing files in my 0022 installation with ones which were for 0012 Arduino (replacing, not adding) as a quick "diff" showed major changes had happened.

I don't really like instructions to "replace these files" when the files are dated 2008, and the files I am replacing are dated 2010. I assume that the Sanguino files are rather old, and while that might make the Sanguino work, it might also stop my Arduino or Mega from working as well.

... so it looks like you don't have the Sanguino pin definitions installed correctly.

Well, someone hasn't got them defined correctly. I didn't write this stuff, you know.

I don't mind if you say "we don't support the Sanguino, sorry", that's fine. But if you also say "these diffs will make it work" that would be helpful, if such diffs exist.

Well, the "cores" directory is supposed to get an additional subdirectory "sanguino" of the sanguino core files, including the pin definitions and what not, so it doesn't directly replace anything. Then the sanguino boards are supposed to pick up the different core files, somehow (and I'm not quite seeing how, since the sanguino add-on to boards.txt says to use the arduino core.)

And I think that change since 12/18 have made it much easier to add new platforms like sanguino, but I'm not sure exactly how. (I really need to find my sanguino board. It's around here somewhere.)

I just tried this on a home brewed Sanguino with all the Sanguino core files copied to the sketchbook/hardware/Sanguino directory (I'm using Linux) and everything works exactly as it should. D13 blinks

Sounds like we are getting a bit closer then.

I went to the "downloads" link as instructed and grabbed the file "Sanguino-0018r2_1_4.zip" which was labelled "0018 hardware folder with unaimed's modified files" and dated June 2010. There didn't seem to be any other software downloads (the other ones were Gerber files for the board etc.).

Now their instructions are:

  1. Copy sanguino-software-1.x/cores/sanguino to arduino-0012/hardware/cores/sanguino
  2. Copy sanguino-software-1.x/bootloaders/atmega644p to arduino-0012/hardware/bootloaders/atmega644p
  3. Copy all the folders in sanguino-software-1.x/libraries/ to arduino-0012/hardware/libraries/ overwriting the existing libraries.

First problem. There is no directory "/cores/sanguino" in the download. It is "/cores/arduino" (see screenshot). So I didn't want to replace all the arduino files with sanguino ones.

I copied the bootloader, no problems, that was just a new file. I fixed up the boards.txt file, no problems there.

I didn't do step 3 because I didn't want to "overwriting ... existing libraries.". And more importantly, as you can see from the screenshot, there is no libraries directory anyway.

This is on a Mac, by the way (although the Windows instructions look virtually identical).

That blinks the correct pin.

Excellent!

I don't really doubt the pin can be made to blink, and I thank you for showing me in a couple of lines of code how to do it, but I wonder if there isn't some problem with the Sanguino with reference to the defines in the standard libraries.

I have never used a Sanguino so I don't know if the reference material is accurate. I had you run the test in case you didn't get replies from someone who has used a Sanguino; someone who could verify that the reference material is accurate. In other words, I wanted to make certain we were starting with accurate information.

But I baulked at replacing files in my 0022 installation with ones which were for 0012 Arduino (replacing, not adding) as a quick "diff" showed major changes had happened.

You made the right choice! It is absolutely not necessary to replace the Arduino core files.

I'll give you instructions based on the layout of the Tiny Core. You should be able to install the Sanguino core by using different directory names. I'll use "{Sketch}" to refer to the Sketch directory on your computer.

  1. I suggest undoing everything you've done so far. Ensure the Arduino IDE is not running. Start by removing the Sanguino entries from the original "boards.txt".

You can and should put third party core files in the {Sketch}\hardware\ directory. Under that directory I have a "tiny" directory where the Tiny Core belongs. I'll use the directory name "sanguino".

  1. Create the directory... {Sketch}\hardware\sanguino\

In my "tiny" directory I have a "boards.txt" file and a "programmers.txt". For the Sanguino, you will not be adding any new programmers but I suggest creating an empty file just in case the IDE needs to be appeased. Later you can try deleting the file.

  1. Create an empty text file... {Sketch}\hardware\sanguino\programmers.txt

The Sanguino boards.txt file includes entries for the AdaBoot bootloader on the 168 and 328 processors. You won't need those for the Sanguino and I suggest leaving them out.

  1. Put the following contents into this file... {Sketch}\hardware\sanguino\boards.txt
ADABoot644P.name=Sanguino - ADABoot loader w/ATmega644p
ADABoot644P.upload.protocol=stk500
ADABoot644P.upload.maximum_size=63488
ADABoot644P.upload.speed=38400

ADABoot644P.bootloader.low_fuses=0xFF
ADABoot644P.bootloader.high_fuses=0xDC
ADABoot644P.bootloader.extended_fuses=0xFD
ADABoot644P.bootloader.path=ADABootloader
ADABoot644P.bootloader.file=ADABoot_644p.hex
ADABoot644P.bootloader.unlock_bits=0x3F
ADABoot644P.bootloader.lock_bits=0x0F

ADABoot644P.build.mcu=atmega644p
ADABoot644P.build.f_cpu=16000000L
ADABoot644P.build.core=sanguino
ADABoot644P.verbose=false
  1. Create the directory... {Sketch}\hardware\sanguino\cores\

  2. Create the directory... {Sketch}\hardware\sanguino\cores\sanguino\

  3. Copy the core files (HardwareSerial.cpp, HardwareSerial.h, Makefile, etcetera) into the directory created above... {Sketch}\hardware\sanguino\cores\sanguino\

  4. Create the directory... {Sketch}\hardware\sanguino\bootloaders\

  5. Create the directory... {Sketch}\hardware\sanguino\bootloaders\ADABootloader\

  6. Copy the bootloader files (ADABoot_644p.hex, etcetera) into the directory created above... {Sketch}\hardware\sanguino\bootloaders\ADABootloader\

That should do it. The Tools menu should now have a "Sanguino - ADABoot loader w/ATmega644p" entry and hopefully works correctly.

Thank you so much. That works perfectly! I have to say your instructions differ substantially from those on the Sanguino web site, and yours work!

I've saved what you said for next time I get a different sort of board.

One query, you said:

Copy the bootloader files (ADABoot_644p.hex, etcetera) into the directory created above... {Sketch}\hardware\sanguino\bootloaders\ADABootloader\

But the supplied bootloader files are actually:

ATmegaBOOT.c
ATmegaBOOT_324P.hex
ATmegaBOOT_644.hex
ATmegaBOOT_644P.hex
Makefile
README.txt

Does that mean the bootloader directory and/or the boards.txt file should be modified to suit the file names?

I have to say your instructions differ substantially from those on the Sanguino web site, and yours work!

Thanks, CodingBadly. The reason that the instructions are so different is that the Arduino authors have done a substantial amount of work to make it EASIER to install non-standard hardware. (You'll notice that you no longer need to modify the "system install" of the arduino environment, for example. Everything can now but done in the particular user's home directory.)

That is great that they have done that. It is a very useful design, and I feel much more comfortable with the revised instructions.

If I may suggest, that particular light has been hidden under a bushel a bit. I never spotted that process documented anywhere (no doubt it is, but no-one pointed me to it).

I just added Sanguino capability to 2 Arduino 0022 installations last weekend: one was Windows XP and the other Linux. In both cases I simply copied the Sanguino folder into the arduino-0022/hardware folder. After burning the Sanguino bootloader into a pair of new 644P chips I was able to upload the blink sketch properly onto them in both the Windows and Linux installations, and pin 13 did indeed do the blink thing. :slight_smile: I have yet to try using any of the libraries, however.

You are welcome! I'm glad it worked.

westfw:
Thanks, CodingBadly

@westfw, you are also welcome!

One query, you said ... ADABoot_644p.hex ... But the supplied bootloader files are actually ... ATmegaBOOT_644P.hex
Does that mean the bootloader directory...

That is one sharp eye you have! You are welcome to change the directory name as you see fit. Just change the entry in boards.txt to match...

ADABoot644P.bootloader.path=ADABootloader

and/or the boards.txt file should be modified to suit the file names?

The entry in boards.txt needs to be changed to match the filename...

ADABoot644P.bootloader.file=ATmegaBOOT_644P.hex

I agree. I hate monkeying (too much ]:D) with the Arduino directory. It's also nice that libraries and third-party cores now survive an upgrade.

If I may suggest, that particular light has been hidden under a bushel a bit. I never spotted that process documented anywhere (no doubt it is, but no-one pointed me to it).

I honestly cannot remember where (or even if) I read about the new directory structure. The only reason I know it so well is from maintaining the Tiny Core.

that particular light has been hidden under a bushel a bit.

I honestly cannot remember where (or even if) I read about the new directory structure.

I tracked it down. It is somewhat described in conjunction with libraries (which makes some sense, but I wish there was a pointer from the "hardware" sections as well.

http://arduino.cc/en/Guide/Environment#libraries where it says:

Third-Party Hardware

Support for third-party hardware can be added to the hardware directory of your sketchbook directory. Platforms installed there may include board definitions (which appear in the board menu), core libraries, bootloaders, and programmer definitions. To install, create the hardware directory, then unzip the third-party platform into its own sub-directory. (Don't use "arduino" as the sub-directory name or you'll override the built-in Arduino platform.) To uninstall, simply delete its directory.

For details on creating packages for third-party hardware, see the platforms page on the Google Code developers site.

And the referenced page has more details:
http://code.google.com/p/arduino/wiki/Platforms