Show Posts
Pages: 1 [2] 3
16  Using Arduino / Installation & Troubleshooting / Re: Bootloading Atmega328p-pu with USBTiny AVR Pocket Programmer on: October 10, 2012, 10:07:10 am
Part 3/3:
Here is the step by step sequence of my activities, so please follow along.  I tried to be as detailed as possible.

I try to run the AVRdude command shown at: https://www.sparkfun.com/products/9825, which is:
avrdude -c usbtiny -B 1 -patmega328 -U flash:w:main.hex
However, avrdude replies that "atmega328" not found.
So, I change to:
avrdude -c usbtinty -B 1 -pm328p -U flash:w:main.hex
However, I get...initialization failed, rc=-1
I read that this may be due to a high baud rate, so I change to:
avrdude -c usbtiny -B 32 -pm328p -U flash:w:main.hex
Now, avrdude is reporting the same thing that Arduino IDE boot load did, i.e.:
avrdude: Device signature = 0x737373
avrdude: Expected signature for ATMEGA328P is 1E 95 0F

So, I follow the same logic as before to change avrdude's expected signature and go to C:\WinAVR-20100110\bin\avrdude.conf and edit the following section to change the signature that Arduino AVRdude uses for the check, as below.

Code:
#------------------------------------------------------------
# ATmega328P
#------------------------------------------------------------

part
    id = "m328p";
    desc = "ATMEGA328P";
    has_debugwire = yes;
    flash_instr = 0xB6, 0x01, 0x11;
    eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00,
 0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF,
 0x99, 0xF9, 0xBB, 0xAF;
    stk500_devcode = 0x86;
    # avr910_devcode = 0x;
# signature = 0x1e 0x95 0x0F;
    signature = 0x73 0x73 0x73;
    pagel = 0xd7;
    bs2 = 0xc2;


Now, when I run,
avrdude -c usbtiny -B 32 -pm328p -U flash:w:main.hex
I get:
avrdude: Device signature = 0x737373
avrdude: NOTE: FLASH memory has not been specified, an erase cycle will be performed.
To disable this feature, specify the -D option.

So I do this and command:
avrdude -c usbtiny -B 32 -pm328p -D -U flash:w:main.hex

Now avrdude complains that "main.hex" No such file or exists, and it is in Safemode with questions:
lfuse was 73, now ff, change back?
lfuse was 7b, now ff, change back?
lfuse was 3, now 7, change back?
I say no to each, as yes causes things to hang up.

I find a copy of "optiboot_atmega328.hex" and use it instead.
Now I command,
avrdude -c usbtiny -B 32 -pm328p -D -U flash:w:optiboot_atmega328.hex
Awsome...things start to Write and read, but still to Device signature 0x737373
and the resulting message for the process is:

Code:
C:\>avrdude -c usbtiny -B 32 -pm328p -D -U flash:w:optiboot_atmega328.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: Device signature = 0x737373
avrdude: reading input file "optiboot_atmega328.hex"
avrdude: input file optiboot_atmega328.hex auto detected as Intel Hex
avrdude: writing flash (32768 bytes):

Writing | ################################################## | 100% 46.03s



avrdude: 32768 bytes of flash written
avrdude: verifying flash memory against optiboot_atmega328.hex:
avrdude: load data flash data from input file optiboot_atmega328.hex:
avrdude: input file optiboot_atmega328.hex auto detected as Intel Hex
avrdude: input file optiboot_atmega328.hex contains 32768 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 43.63s



avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0xff != 0x00
avrdude: verification error; content mismatch

avrdude: safemode: lfuse changed! Was 73, and is now 0
Would you like this fuse to be changed back? [y/n] n
avrdude: safemode: hfuse changed! Was 7b, and is now 0
Would you like this fuse to be changed back? [y/n] n
avrdude: safemode: efuse changed! Was 3, and is now 0
Would you like this fuse to be changed back? [y/n] n
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

All looked good, except the verification process, AND it does not look like the fuses were set properly, AND I still have this annoying Device signature issue.
In the end, even though this occurs, I guess this is why I cannot load a Blink sketch through Arduino IDE, as I get the following error in Arduino IDE trying to upload the sketch...

Code:
avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\arduino-1.0\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : \\.\COM4
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Recv:
avrdude: stk500_getsync(): not in sync: resp=0x00

avrdude done.  Thank you.

Sorry for the long winded explanation, but I wanted all the details out there for whomever can help me here.
Otherwise, I just go and spend the extra $1 for a pre-boot loaded chip and succumb to failure as a boot loader.

Thanks for any advice and help.

 
17  Using Arduino / Installation & Troubleshooting / Re: Bootloading Atmega328p-pu with USBTiny AVR Pocket Programmer on: October 10, 2012, 09:59:06 am
Part 2/3:
So I accept the fate of my chips having a different signature than expected, so I go and change the expectation to move forward.
If I go to Arduino-1.0/hardware/tools/avr/etc/avrdude.conf and edit the following section to change the signature that Arduino AVRdude uses for the check, as below.

Code:
#------------------------------------------------------------
# ATmega328P
#------------------------------------------------------------

part
    id = "m328p";
    desc = "ATMEGA328P";
    has_debugwire = yes;
    flash_instr = 0xB6, 0x01, 0x11;
    eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00,
 0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF,
 0x99, 0xF9, 0xBB, 0xAF;
    stk500_devcode = 0x86;
    # avr910_devcode = 0x;
#    signature = 0x1e 0x95 0x0F;    
signature = 0x73 0x73 0x73;
    pagel = 0xd7;

With this change I then get the following result from boot loader:

Code:
C:\Program Files (x86)\arduino-1.0\hardware/tools/avr/bin/avrdude -CC:\Program Files (x86)\arduino-1.0\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -cusbtiny -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xde:m -Ulfuse:w:0xff:m

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\arduino-1.0\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : lpt1
         Using Programmer              : usbtiny
avrdude: usbdev_open(): Found USBtinyISP, bus:device: bus-0:\\.\libusb0-0001--0x1781-0x0c9f
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
CMD: [ac 53 00 00] [00 00 53 53]
avrdude: AVR device initialized and ready to accept instructions

Reading | CMD: [30 00 00 00] [53 73 73 73]
CMD: [30 00 01 00] [73 73 73 73]
################CMD: [30 00 02 00] [73 73 73 73]
################################## | 100% 0.01s

avrdude: Device signature = 0x737373
CMD: [a0 03 fc 00] [73 f3 f3 ff]
CMD: [a0 03 fd 00] [ff ff ff ff]
CMD: [a0 03 fe 00] [ff ff ff ff]
CMD: [a0 03 ff 00] [ff ff ff ff]
avrdude: erasing chip
CMD: [ac 80 00 00] [ff ff ff ff]

avrdude done.  Thank you.

This all occurs way to fast and it is not boot loading.


So, I give up on boot loading from Arduino IDE and go directly to the Avrdude.....
See next message for the steps I followed next....
18  Using Arduino / Installation & Troubleshooting / Bootloading Atmega328p-pu with USBTiny AVR Pocket Programmer on: October 10, 2012, 09:57:14 am
Sorry ahead of time for the large message, but I know that details are usually appreciated in helping debug issues.
This is Part 1 of a few Parts, because of the exceeded size limit smiley-grin
I am having problems boot loading and loading sketches to the Atmega328p-pu chip.
Let me start by defining a few things:
I am using a windows 7 (64bit) platform
Arduino IDE 1.0
Avrdude 5.10
Pocket AVR programmer (https://www.sparkfun.com/products/9825
FT232RL USB to Serial breakout board (https://www.sparkfun.com/products/718)

And I followed the procedure to build a breadboard for boot loading and programming from: http://itp.nyu.edu/physcomp/Tutorials/ArduinoBreadboard
I quadruple checked my setup numerous times to make sure it was correct.
Note:  I did have to pin test the AVR programmer 6-pin connector and found that it has to be inserted in the opposite direction as shown in step 6.3 http://itp.nyu.edu/physcomp/uploads/arduinobload_plugin.jpg.  The supplied 6-pin has to go in the opposite direction from what is shown in this image.

Step 6.4 "Time to Burn" does not work and lead me down the following path:  Using AVRdude directly for the boot load.

I had issues getting the drivers all installed, but in the end, I basically followed the procedure details outlined by BeagleBoy at the top of the comments list at: https://www.sparkfun.com/products/9825
It did not work fist time and had to uninstall and reinstall a couple of times, but in the end, I have the following results in DeviceManager when both the Programmer and USB FT232RL are plugged in:
Device Manager:  (Partial list)
- LibUSB-Win32 Devices
  - USBtiny
- Ports (Com & LPT)
  - USB Serial Port (COM4)
- Other Devices
  - Unknown device

To try using the Arduino IDE 1.0 to program the boot loader, I do the following:
Tools/Board:  Set to Arduino Uno
Tools/Serial Port:  Com4 is selected and recognized, i.e. the FT232R is seen.
Tools/Programmer: Set to USBtinyISP
Files/Preferences:  select verbose output for both compilation and upload.
Then, running Tools/Burn Bootloader, I recieve the following message:

Code:
C:\Program Files (x86)\arduino-1.0\hardware/tools/avr/bin/avrdude -CC:\Program Files (x86)\arduino-1.0\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -cusbtiny -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xde:m -Ulfuse:w:0xff:m

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\arduino-1.0\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : lpt1
         Using Programmer              : usbtiny
avrdude: usbdev_open(): Found USBtinyISP, bus:device: bus-0:\\.\libusb0-0001--0x1781-0x0c9f
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
CMD: [ac 53 00 00] [00 00 53 53]
avrdude: AVR device initialized and ready to accept instructions

Reading | CMD: [30 00 00 00] [53 73 73 73]
CMD: [30 00 01 00] [73 73 73 73]
################CMD: [30 00 02 00] [73 73 73 73]
################################## | 100% 0.01s

avrdude: Device signature = 0x737373
avrdude: Expected signature for ATMEGA328P is 1E 95 0F
         Double check chip, or use -F to override this check.

avrdude done.  Thank you.

I think that the bottom line is that the Device Signature is wrong.  I have tried a couple of chips and each returns 0x737373 for the signature.  I also noticed that in the message above it says "avrdude: programmer operation not supported".  Not sure if this is also an issue or not.
My largest issue is WHY do I always get a 0x737373 return from any of the Atmega328p-pu chips that I put in?
Shouldn't it be reading 1E 95 0F for this chip???

Next step in next message below...
19  Development / Other Software Development / Re: New fast digital I/O and Software SPI libraries on: October 04, 2012, 06:46:37 am
fat16lib,
This library is just the idea that I needed for my project as I have been trying to make my own bit-blast SPI protocol, as I need to use pins other than 50,51,52,53 for my SPI calls.
I have my own crude bit-blast working, but I would like to take advantage of other device libraries, for example the MCP23S17 library, that are written for the SPI library, but I want to shift SPI over to pins 32, 34,36,38 on my Mega2560.

However, I'm having problems getting any signal from the GPIO pins on my Mega2560 using the SoftSPI library, or demo.
The below modified pin assigned demo compiles just fine with no errors, but when I probe pins 38 (CLK) or pins 36,34 I see nothing.  Any ideas?

Also, I have a basic question about the SS line...
The standard SPI library includes the use of SS pin to select/deselect the slave, but I don't see the use of SS in this library, or example.  Should the spi.transfer() calls be bounded calls to pull SS LOW,HIGH?
Why was the use of SS not included?

Code:
// scope test for development - assumes 328 processor
#include <DigitalPin.h>
#include <SoftSPI.h>

const uint8_t SOFT_SPI_MISO_PIN = 36;
const uint8_t SOFT_SPI_MOSI_PIN = 34;
const uint8_t SOFT_SPI_SCK_PIN  = 38;
const uint8_t SPI_MODE = 0;

SoftSPI<SOFT_SPI_MISO_PIN, SOFT_SPI_MOSI_PIN, SOFT_SPI_SCK_PIN, SPI_MODE> spi;

int test;
void setup() {
  Serial.begin(9600);
  spi.begin();
  while(1) {
    Serial.println("Enter:");
    Serial.println("R - Receive");
    Serial.println("S - Send");
    Serial.println("T - Transfer");
    while ((test = Serial.read()) <= 0) {}
    test = toupper(test);
    if (strchr("RST", test)) break;
    Serial.println("Invalid entry");
  };
  Serial.print("Starting test ");
  Serial.println((char)test);
}
void loop() {
  if (test == 'S') spi.send(0X55);
  if (test == 'R') {
    Serial.println(spi.receive(), HEX);
  }
  if (test == 'T') {
    Serial.println(spi.transfer(0XAA), HEX);
  }
  delay(10);
}
20  Using Arduino / Programming Questions / Re: Beginner questions: Using the MCP4261 library on: May 25, 2012, 03:50:41 pm
Update...
So, I can get the LSB if I brute-force the method as below..
But I would rather use the SPI library, as I suspect that it is more efficient than this approach. 
BTW, as you can see, this is just a quick test with the Pot addrs and cmd hard coded into the commandbits parameter.

Code:
    Serial.println("***********readWiper1 brut force******************");
     //set pin modes
     pinMode(DIGIPOT1_CS, OUTPUT);
     pinMode(DATAOUT, OUTPUT);
     pinMode(DATAIN, INPUT);
     pinMode(SPICLOCK, OUTPUT);
     //disable device to start with
     digitalWrite(DIGIPOT1_CS,HIGH);
     digitalWrite(DATAOUT,LOW);
     digitalWrite(SPICLOCK,LOW);
   
    digitalWrite(DIGIPOT1_CS,LOW); //Enable Pot1
    byte commandbits = B00011100; //command bits - XXXX address, YY cmd, ZZ Error & data
    for (int i=7; i>=0; i--){
      digitalWrite(DATAOUT,(unsigned int)commandbits>>i);
      //cycle clock
      digitalWrite(SPICLOCK,HIGH);
      digitalWrite(SPICLOCK,LOW);   
    }
    byte ReadPotValue = 0b00000000;
    for (int i=7; i>=0; i--){
      ReadPotValue += digitalRead(DATAIN)<<i;
      //cycle clock
      digitalWrite(SPICLOCK,HIGH);
      digitalWrite(SPICLOCK,LOW);   
    }
    Serial.print("ReadPotValue = ");
    Serial.println(ReadPotValue, BIN);
    Serial.print("ReadPotValue = ");
    Serial.println(ReadPotValue);


But, I would still like to know why SPI.transfer() return parameter returns a value that is shifted right 1 bit and removes the LSB.

Any thoughts?

Thanks,
21  Using Arduino / Programming Questions / Re: Beginner questions: Using the MCP4261 library on: May 25, 2012, 11:51:27 am
Hi,
I have been using the MCP4261 library successfully to set the wiper0 and wiper1, so all is good in that area.  In fact, I have the SPI running over RS485 Full-Duplex at 4Mbs over 3 meter RJ45 cabling.
My problem has to do with the READ function of the chip.
I send a 16bit word in two 8 bit sends, as in the "send16BitCmd(uint8_t addr, uint8_t cmd, int data)" function in the Library.
I had to add the below function to the library, to send the #define CMD_READ_DATA  0b11 value to tell the MCP4261 to READ.
Code:
void MCP4261::readWiper(int wiper, int value) {
  uint8_t wiperAddr;
  //int retData;
  if ((value >= 0) && (value <= 256)) {
    wiperAddr = getWiperAddr(wiper);
    send16BitCmd(wiperAddr, CMD_READ_DATA, value);
  }
  //return retData;
}

This all seems to send out the correct bits, as...
outByte0 = b0001 1100  (for Wiper address 1, and the 1100 sets the mode to READ.
outByte1 = b0000 0000  (really,, i think that you can send anything for the data Byte)
each Byte gets sent out by SPI.transfer(), again using the  "send16BitCmd(uint8_t addr, uint8_t cmd, int data)" function.

Now the problem comes in as I expect that the Return values, inByte1 and inByte0, from "inByte1 = SPI.transfer(outByte1);" calls in the library will return the previously written Bytes.

It kind of does, but I ALWAYS get a return from inByte0 = 1111 1111
and inByte1 seems to be shifted by 1 bit lopping off the LSB.

Can anyone help me to understand where the LSB has gone in my READ?

I basically am doing this to check that the transmission was taken, as an error check.

Thank for any help.

22  Using Arduino / Project Guidance / Re: Help with .htm files on Ethernet Shield on: February 15, 2012, 09:34:42 am
OK, Problem solved.  Rookie mistake.
I was not allowing additional posts pass threw my code to catch the .js and .png handshakes.
Works fine now.
23  Using Arduino / Project Guidance / Re: Help with .htm files on Ethernet Shield on: February 14, 2012, 02:55:44 pm
Here is an example of the htm file and js file.

CHART1.htm on root directory of SD card.
Code:
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="arduino.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="chart1.js"></script>
</head>
<body>
<div id="head1">Enclosure Temperature</div>
<div id="chart1"></div>
<div id="foot1">Powered By <a href="http://www.arduino.cc/"><img src="arduino.png" alt="arduino" style="vertical-align: middle;"/></a></div>
</body>
</html>

Chart1.js on the root directory of SD card.
Code:
// Load the Visualization API
google.load('visualization', '1', {'packages':['corechart']});
var temp_interval = 300000;
$(function(){
  update_temp();
});
function update_temp(){
  $("#chart").html("Loading ...");
  $.get('Weather.csv', function(data) {
    $("#chart").html("");
    var chart_data = new google.visualization.DataTable();
    chart_data.addColumn('string', 'Time');
    chart_data.addColumn('number', 'Temp');
    var lines = data.split("\n");
    chart_data.addRows(lines.length - 1);
    output = "";
    for(i = 0; i < lines.length - 1; i++){
      line = $.trim(lines[i]);
      parts = line.split(",");
      time = parts[0];
      temp1 = parts[1];
      time_rex = /\d+ (\d+-\d+-\d+ \d+:\d+:\d+).*/;
      matches = time.match(time_rex);
//      date_time = matches[1];
      chart_data.setValue(i, 0, time);
      chart_data.setValue(i, 1, parseFloat(temp1));
    }
    var chart1 = new google.visualization.LineChart(document.getElementById('chart1'));
    chart1.draw(chart_data, {width: 640, height: 480, title: 'Enclosure Temperature'});
   });
  setTimeout("update_temp()",temp_interval);
}
24  Using Arduino / Project Guidance / Re: Help with .htm files on Ethernet Shield on: February 14, 2012, 02:53:43 pm
To add some more info...

Below is a section of the code that does not work, but uses identical methods, i.e. open a file, selected by <a href= tag.  This works.
This is called from the loop() main routine.
Reads the filename from the "Get" and does the same "client.print" to the client.   This all works.
Again, in the browser I can "view page source" and see that all the Html code is getting sent to the client, exactly like when it works.  However, All I end up seeing is "Enclosure Temperature" and "Powered By" with a broken link to the arduino.png file.
So it seems to not execute the scripts or display the little "arduino.png" image, as the working code does.  I'm not sure why.

Code:
void Weather(){
    
  
  EthernetServer server(port);              // port 80 is default for HTTP

  
  EthernetClient client = server.available();
    index = 0;
    while (client.connected()) {
      if (client.available()) {
        c = client.read();
 
        // If it isn't a new line, add the character to the buffer
        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          // are we too big for the buffer? start tossing out data
          if (index >= BUFSIZ)
            index = BUFSIZ -1;
          
          // continue to read more data!
          continue;
        }

        // got a \n or \r new line, which means the string is done
        clientline[index] = 0;

        if (strstr(clientline, "W001") != 0){  //Got the RETURN Button Pressed
            ClientPrintln("<html>", client);
            ClientPrintln("<head>", client);
            ClientPrintln("<title>Weather</title>", client);
            ClientPrintln("</head>", client);
            ClientPrintln("<META HTTP-EQUIV='REFRESH' CONTENT='0' URL=>", client);

            // webpage title
            client.println("<h1>Weather Station</h1><hr>");

            ClientPrintln("<b><label for='text1'><a href = \"CHART1.htm\">Enclosure Temp: </a><input type='text' size='20' disabled='disabled' maxlength='20' style='background-color:yellow; color=black;' value='", client);
            client.print(str_Temp1);
            ClientPrintln(" C' id='text1'/></label></b>", client);
            ClientPrintln("<br>", client);
            ClientPrintln("<b><label for='text1'>Enclosure Pressure: <input type='text' size='20' disabled='disabled' maxlength='20' style='background-color:yellow; color=black;' value='", client);
            client.print(str_Baro1);
            ClientPrintln(" Pa' id='text1'/></label></b>", client);
            ClientPrintln("<br>", client);
            ClientPrintln("<b><label for='text1'>Outside Temp: <input type='text' size='20' disabled='disabled' maxlength='20' style='background-color:yellow; color=black;' value='", client);
            client.print(str_Temp2);
            ClientPrintln("' id='text1'/></label></b>", client);
            ClientPrintln("<br>", client);
            ClientPrintln("<b><label for='text1'>Outside Pressure: <input type='text' size='20' disabled='disabled' maxlength='20' style='background-color:yellow; color=black;' value='", client);
            client.print(str_Baro2);
            ClientPrintln(" Pa' id='text1'/></label></b>", client);
            ClientPrintln("<br>", client);
            ClientPrintln("<b><label for='text1'>Outside Temp: <input type='text' size='20' disabled='disabled' maxlength='20' style='background-color:yellow; color=black;' value='", client);
            client.print(str_Temp3);
            ClientPrintln(" C' id='text1'/></label></b>", client);
            ClientPrintln("<br>", client);
            ClientPrintln("<b><label for='text1'>Outside Humidity: <input type='text' size='20' disabled='disabled' maxlength='20' style='background-color:yellow; color=black;' value='", client);
            client.print(str_Humid);
            ClientPrintln(" %RH' id='text1'/></label></b>", client);

            ClientPrintln("<form  method='get' name='form'>", client);
            ClientPrintln("<button style='background-color:silver; color=black; height:40px; width:150px' name='W001' value=1 type='submit' >Return to Main</button>", client);
            ClientPrintln("</form>", client);
            ClientPrintln("</body>", client);
            ClientPrintln("</html>", client);
            ReadLogs = false;
            GotoMain = true;
            GotoAdmin = false;
            GotoChangeUser = false;
            GotoWeather = false;

        } else if (strstr(clientline, "GET /CHART") != 0){
            char *filename2;
            filename2 = clientline + 5; // look after the "GET /" (5 chars)
            // a little trick, look for the " HTTP/1.1" string and
            // turn the first character of the substring into a 0 to clear it out.
            (strstr(clientline, " HTTP"))[0] = 0;
            
            // print the file we want
            Serial.print("filename = ");
            Serial.println(filename);
            
           if (!file.open(&root, filename2, O_READ)) {
              ClientPrintln("HTTP/1.1 404 Not Found", client);
              ClientPrintln("Content-Type: text/html", client);
              ClientPrintln("", client);
              ClientPrintln("<h2>File Not Found!</h2>", client);
              break;
            }
            Serial.println("Opened!");
                      
            client.println("HTTP/1.1 200 OK");
            
            //Set appropriate mime type based on file extension
            String fname = String(filename2);
            int dotat = fname.lastIndexOf('.');
            String extension = String("");
            if(dotat > -1){
              extension = String(fname.substring(dotat+1));
            }
  
            extension.toLowerCase();
            
            Serial.print("extension is ");
            Serial.println(extension);
            
            if(extension == "htm"){
              client.println("Content-Type: text/html");
            }
            else if(extension == "js"){
              client.println("Content-Type: application/x-javascript");
            }
            else if(extension == "css"){
              client.println("Content-Type: text/css");
            }
            else if(extension == "jpg"){
              ClientPrintln("Content-Type: image/jpeg", client);
            }
            else if(extension == "gif"){
              ClientPrintln("Content-Type: text/gif", client);
            }
            else if(extension == "png"){
              ClientPrintln("Content-Type: image/png", client);
            }
            else{
              ClientPrintln("Content-Type: text/plain", client);
            }    
        
            client.println();
            
            char c;
            while ((c = file.read()) >= 0) {
              //c = file.read();
              client.print(c);
            }
            file.close();
          
        } else {
          
        //Same as above, but with...
         ClientPrintln("<META  URL=>", client); //to remove not have a 0 second refresh.  I use the 0 second refresh when I change pages in my project...
        }
        
        break;
      }
    }

    // give the web browser time to receive the data
    delay(1);
    client.stop();
    
}
25  Using Arduino / Project Guidance / Help with .htm files on Ethernet Shield on: February 14, 2012, 02:49:40 pm
Hello,
I am having some problems porting the below code, that works great.  I would include all the code, but let me start here first.
When I port this code to my new project, the htm file gets sent, and I can see it when I "view page source" in the browser.  It looks identical to what gets served in the working code.
It just seems like it has lost its brains as to where to access the scripts or png files, etc, or I am just missing something else fundamentally.
Can someone help me understand what is going on?  Thanks ahead of time.
Sorry ahead of time for some of the "work-in-progress" commented lines and somewhat newbie architecture.

Below is the code that works. (from aaron at the Roaming Coder)  I had to slightly update for use with Arduino 1.0, but pretty minor.  I also removed the TimeServer parts, for simplicity, but this code works to simply list the files on the SD card and select an htm file to display and run the javascripts.  I really liked this because it seemed really an easy way to graph my weather data that I collect on the SD card.
Code:
#include <SPI.h>
#include <SD.h>
#include <Ethernet.h>

/************ ETHERNET STUFF ************/
byte mac[] = { 0x, 0x, 0x, 0x, 0x, 0x }; // my MAC is inserted
byte ip[] = { 192, 168, 0, 50 };
EthernetServer server(XXXX);  // My forwarded Port is inserted

/************ SDCARD STUFF ************/
Sd2Card card;
SdVolume volume;
SdFile root;
File file;
const int chipSelect = 4;  

const int temp_pin = 0;
const int light_pin = 1;
unsigned long sample_delay_interval = 600000;  //one minute
unsigned long last_temp_sample_millis = 0;
String TempString = "";

// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))

void error_P(const char* str) {
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}

void setup() {
  Serial.begin(9600);
//  analogReference(INTERNAL);
 
  PgmPrint("Free RAM: ");
  Serial.println(FreeRam());  
  
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  pinMode(10, OUTPUT);                       // set the SS pin as an output (necessary!)
  digitalWrite(10, HIGH);                    // but turn off the W5100 chip!

  if (!card.init(SPI_FULL_SPEED, chipSelect)) error("card.init failed!");
  SD.begin(chipSelect);
  
  // initialize a FAT volume
  if (!volume.init(&card)) error("vol.init failed!");

  PgmPrint("Volume is FAT");
  Serial.println(volume.fatType(),DEC);
  Serial.println();
  
  if (!root.openRoot(&volume)) error("openRoot failed");

  // list file in root with date and size
  PgmPrintln("Files found in root:");
  root.ls(LS_DATE | LS_SIZE);
  Serial.println();
  
  // Recursive list of all directories
  PgmPrintln("Files found in all dirs:");
  root.ls(LS_R);
  
  Serial.println();
  PgmPrintln("Done");
  
  // Debugging complete, we start the server!
  Ethernet.begin(mac, ip);
  server.begin();
}

void ListFiles(EthernetClient client, uint8_t flags) {
  // This code is just copied from SdFile.cpp in the SDFat library
  // and tweaked to print to the client output in html!
  dir_t p;
  
  root.rewind();
  client.println("<ul>");
  while (root.readDir(p) > 0) {
    // done if past last used entry
    if (p.name[0] == DIR_NAME_FREE) break;

    // skip deleted entry and entries for . and  ..
    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.') continue;

    // only list subdirectories and files
    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;

    // print any indent spaces
    client.print("<li><a href=\"");
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if (i == 8) {
        client.print('.');
      }
      client.write(p.name[i]);
    }
    client.print("\">");
    
    // print file name with possible blank fill
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if (i == 8) {
        client.print('.');
      }
      client.write(p.name[i]);
    }
    
    client.print("</a>");
    
    if (DIR_IS_SUBDIR(&p)) {
      client.print('/');
    }

    // print modify date/time if requested
    if (flags & LS_DATE) {
       root.printFatDate(p.lastWriteDate);
       client.print(' ');
       root.printFatTime(p.lastWriteTime);
    }
    // print size if requested
    if (!DIR_IS_SUBDIR(&p) && (flags & LS_SIZE)) {
      client.print(' ');
      client.print(p.fileSize);
    }
    client.println("</li>");
  }
  client.println("</ul>");
}

// How big our line buffer should be. 100 is plenty!
#define BUFSIZ 100

void loop()
{
  char clientline[BUFSIZ];
  int index = 0;
  
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    
    // reset the input buffer
    index = 0;
    
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        // If it isn't a new line, add the character to the buffer
        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          // are we too big for the buffer? start tossing out data
          if (index >= BUFSIZ)
            index = BUFSIZ -1;
          
          // continue to read more data!
          continue;
        }
        
        // got a \n or \r new line, which means the string is done
        clientline[index] = 0;
        
        // Print it out for debugging
        Serial.println(clientline);
        
        // Look for substring such as a request to get the root file
        if (strstr(clientline, "GET / ") != 0) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          
          // print all the files, use a helper to keep it clean
          client.println("<h2>Files:</h2>");
          ListFiles(client, LS_SIZE);
        } else if (strstr(clientline, "GET /") != 0) {
          // this time no space after the /, so a sub-file!
          char *filename;
          
          filename = clientline + 5; // look after the "GET /" (5 chars)
          // a little trick, look for the " HTTP/1.1" string and
          // turn the first character of the substring into a 0 to clear it out.
          (strstr(clientline, " HTTP"))[0] = 0;
          
          // print the file we want
          Serial.println(filename);

          file = SD.open(filename);
          if (!file) {
            client.println("HTTP/1.1 404 Not Found");
            client.println("Content-Type: text/html");
            client.println();
            client.println("<h2>File Not Found!</h2>");
            break;
          }
          
          Serial.println("Opened!");
                    
          client.println("HTTP/1.1 200 OK");
          
          //Set appropriate mime type based on file extension
          String fname = String(filename);
          int dotat = fname.lastIndexOf('.');
          String extension = String("");
          if(dotat > -1){
            extension = String(fname.substring(dotat+1));
          }

          extension.toLowerCase();
          
          Serial.print("extension is ");
          Serial.println(extension);
          
          if(extension == "htm"){
            client.println("Content-Type: text/html");
          }
          else if(extension == "js"){
            client.println("Content-Type: application/x-javascript");
          }
          else if(extension == "css"){
            client.println("Content-Type: text/css");
          }
          else if(extension == "jpg"){
            client.println("Content-Type: image/jpeg");
          }
          else if(extension == "gif"){
            client.println("Content-Type: text/gif");
          }
          else if(extension == "png"){
            client.println("Content-Type: image/png");
          }
          else{
            client.println("Content-Type: text/plain");
          }      
          client.println();
          
          char c;
          while (file.available()) {
            c = file.read();
            client.print(c);
          }
          file.close();
        } else {
          // everything else is a 404
          client.println("HTTP/1.1 404 Not Found");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<h2>File Not Found!</h2>");
        }
        break;
      }
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
}

26  Using Arduino / Installation & Troubleshooting / Re: Time Library in Arduino 1.0 on: January 23, 2012, 10:55:46 am
dumle29,
Thanks for the input.  If you look at my print.txt of my directories, you will see that 3 directories came with the Time Library...
\libraries\Time
\libraries\TimeAlarms
\libraries\DS1307RTC

I have no idea what that last one is for, however.
What am I missing, and where can I get the latest?

BTW.  I have temporarily created and tested my own function to convert Epoch to the current Month\Day\Year hh:mm:ss results.  So my need has lessened however it still bugs me that I cannot get this library to work.

Thank again.
27  Using Arduino / Installation & Troubleshooting / Re: Loading Sketches Problem with Mega2560 and Ethernet Shield on: January 21, 2012, 04:06:21 pm
zoomkat,
Thanks.  Good info for me.  I will check this out. 
For now, during development, I can deal with it.  After I install the final solution, it would be preferable that future upgrades to code do not require me opening the panel and pulling off the board.
Thanks.
28  Using Arduino / Installation & Troubleshooting / Re: Loading Sketches Problem with Mega2560 and Ethernet Shield on: January 21, 2012, 01:52:57 pm
zoomkat,
Understood, but I'm not clear if this only applies once you add the PoE module, or if it remains true even without.
However, if you look at my original procedure, above, it still does not explain why, even with the Ethernet removed, I have to go through the upload process twice.  Once with a failure to load, then the second is successful.  This is VERY reproducible.
This does not occur with other simple example sketches, non Ethernet Sketches.  However, I have not tested to see if Ethernet simple examples load the first time.
I can test that.
Even so, I'm not sure what is going on.  Is it possible that something in my Sketch is causing the issue, even though I have absolutely no errors in the compile?

29  Using Arduino / Installation & Troubleshooting / Re: Loading Sketches Problem with Mega2560 and Ethernet Shield on: January 21, 2012, 12:35:39 pm
zoomkat,

This is the exact model..
http://arduino.cc/en/Main/ArduinoEthernetShield

In the description, it states...
"The shield does not come with the PoE module built in, it is a separate component that must be added on."

30  Using Arduino / Installation & Troubleshooting / Re: Loading Sketches Problem with Mega2560 and Ethernet Shield on: January 21, 2012, 12:25:50 pm
zoomkat,
Thanks.  I forgot that detail smiley-razz
It is a Wiznet chip model: Arduino Ethernet Shield Ethernet (R3)

Does the R3 mean with PoE support?
Pages: 1 [2] 3