Show Posts
Pages: [1] 2 3 ... 196
1  Using Arduino / Programming Questions / Re: Problem with W5100 [Ethernet] on: September 25, 2014, 12:17:23 pm
I come in late on this, but as PaulS is implying, if you think something is not working, then it's best to wipe everything else out of the program [all the other "crap"], and just address the one single issue.

That's also the ONLY way to write code in the first place. Get each of the different subsystems working in isolation from everything else, and THEN put them together. Then, the 2nd guessing [especially by forum members] is minimal.

The other thing is, your original post indicated there may also be a power issue:
Quote
Sometimes it has power but when you plug in the ethernet cable nothing happens on the breakout board. Not even a single LED on the Female connector is flashing.
I just had a problem yesterday where my SD card shield stopped working. Turned out to be the flakey female headers on the Arduino board were not making good contact with the flakey shield pins, so I bent the pins slightly. The problem is, none of these pins or receptacles are square - like they ought to be - but they're either flat or spade, and good contact may be iffy.
2  Using Arduino / Programming Questions / Re: accessing a variable in wiring.c on: September 25, 2014, 11:55:59 am
Bad night, last night, oof. Was also dealing with a flakey SD shield - turned out to be those half-reliable female headers on the Arduino board not making good contact, so bent the pins. It's all working now.

For reference, my basic plan for all this was to hack into ISR(TIMER0_OVF_vect), and make some minor changes [ie, use to modify the above mentioned variables], and then access the variables from my sketches.

I do believe it would be best practice to add an accessor function to wiring.c to actually get the variable, vs having sketches access the variables directly.  This is because the multi-byte volatiles are not updated atomically and it is possible for a thread running at non-interrupt-priority to obtain inconsistent values when reading a long that is updated in an ISR.  Accesses to these types should be bracketed by a CLI/SEI.  This logic can easily be put into a simple accessor function, simplifying and de-risking the main program design.
Thanks for the suggestion. I actually had written an accessor function, but it wouldn't work either due to the referencing problem [even with a fcn prototype in Arduino.h]. All good now. Thanks.
3  Using Arduino / Programming Questions / Re: accessing a variable in wiring.c on: September 25, 2014, 02:18:08 am
Foo, talk about a complete screw up. I was sure I had tried this earlier, but I guess not.

As it turns out, it compiles fine for all of the regular Arduino boards, but not for any of the mega1284 boards, either from the maniacbug 1284 library, or the latest Moteino-Mega board [which uses the 1284 - don't ask me why he calls it a -Mega].

That explains the whole thing. maniac-1284 has its own core files. Double-foo. Sorry, my screw-up.
4  Using Arduino / Programming Questions / Re: accessing a variable in wiring.c on: September 25, 2014, 01:47:12 am
There's nothing to it - same as the other guys - maybe I'm just going batty - and time to sleep. Am using IDE v.1.05 here.

The timer0_millis part works fine.
Code:
/*
file: test_ecnt
revised: 09/24/14.
************************************************/

extern volatile unsigned long eCnt1;
extern volatile unsigned int eCnt2;
extern volatile unsigned long timer0_millis;

void setup()
{
  Serial.begin(57600);
}

void loop()
{
  Serial.println( eCnt1 );
  Serial.println( timer0_millis );
  delay(2000);
}

Mods to wiring.c
Code:
volatile unsigned long timer0_overflow_count = 0;
volatile unsigned long timer0_millis = 0;
static unsigned char timer0_fract = 0;

//ADDED 09/24/14.
volatile unsigned long eCnt1=0;
volatile unsigned int eCnt2=0;
 
 
#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ISR(TIM0_OVF_vect)
#else
ISR(TIMER0_OVF_vect)
#endif
{
// copy these to local variables so they can be stored in registers
// (volatile variables must be read from memory on every access)
unsigned long m = timer0_millis;
unsigned char f = timer0_fract;

m += MILLIS_INC;
f += FRACT_INC;
if (f >= FRACT_MAX) {
f -= FRACT_MAX;
m += 1;
}
timer0_fract = f;
timer0_millis = m;
timer0_overflow_count++;

//ADDED 09/24/14.
eCnt1++;
eCnt2++;
}

Errors
Code:
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega1284p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -IC:\Documents and Settings\Wanderer\My Documents\Arduino\hardware\tredici\cores\standard -IC:\Documents and Settings\Wanderer\My Documents\Arduino\hardware\tredici\variants\tredici C:\Documents and Settings\Wanderer\My Documents\Arduino\hardware\tredici\cores\standard\WMath.cpp -o C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\WMath.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega1284p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -IC:\Documents and Settings\Wanderer\My Documents\Arduino\hardware\tredici\cores\standard -IC:\Documents and Settings\Wanderer\My Documents\Arduino\hardware\tredici\variants\tredici C:\Documents and Settings\Wanderer\My Documents\Arduino\hardware\tredici\cores\standard\WString.cpp -o C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\WString.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\WInterrupts.c.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\wiring.c.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\wiring_analog.c.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\wiring_digital.c.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\wiring_pulse.c.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\wiring_shift.c.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\CDC.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\HardwareSerial.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\HID.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\IPAddress.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\main.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\new.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\Print.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\Stream.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\Tone.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\USBCore.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\WMath.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-ar rcs C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\WString.cpp.o
C:\winapps\ArduinoIDE\v1.0.5\hardware\tools\avr\bin\avr-gcc -Os -Wl,--gc-sections -mmcu=atmega1284p -o C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\test_ecnt.cpp.elf C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\test_ecnt.cpp.o C:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp\core.a -LC:\DOCUME~1\Wanderer\LOCALS~1\Temp\build2553182313848906727.tmp -lm
test_ecnt.cpp.o: In function `loop':
C:\winapps\ArduinoIDE\v1.0.5/test_ecnt.ino:18: undefined reference to `eCnt1'
C:\winapps\ArduinoIDE\v1.0.5/test_ecnt.ino:18: undefined reference to `eCnt1'
C:\winapps\ArduinoIDE\v1.0.5/test_ecnt.ino:18: undefined reference to `eCnt1'
C:\winapps\ArduinoIDE\v1.0.5/test_ecnt.ino:18: undefined reference to `eCnt1'
5  Using Arduino / Programming Questions / Re: Comments requested on tutorial for function pointers on: September 25, 2014, 01:19:53 am
The link helps, I think. My feeling when looking at your page initially, was what exactly is the difference between a pointer to function and a callback? In regards overcomplication, I posted the entire library fcn for reference, but it can easily be reduced to its fundamental details. And the basic idea between give and take described. In any case, I'm only making "suggestions", you don't need to take them too seriously :-). I just know I learned a huge amount from this example, even if the library never worked properly.

Code:
/*
*  misc handshake and error checking is left out for clarity.
*****************************************************************/
bool CameraC328R::getPictureData( void (*callback)(uint32_t startpos, uint16_t datalen, byte* buff) )
{
  .... (declare local variables) ....
  byte holdBuff[64];                 // holding buffer for camera data.

  // access sequence of data packets, and transfer to calling sketch using callback.
  while( !end_of_image() ) {
    if( waitForData(holdBuff) ) {                  // wait for the next data packet.  
      callback( picDataPos, 64, holdBuff );    // transfer to main program.

      .... (perform requisite handshakes, indexing, and error-checking) ....

      picDataPos += 64;  // advance index in image.
    }
  }
}
6  Using Arduino / Programming Questions / Re: Comments requested on tutorial for function pointers on: September 25, 2014, 12:04:12 am
Hi Nick, good job re function pointers at gammon.com.au - as always. I thought I'd make a couple of suggestions.

1. you might spend a little more time defining what "callback" or "callback function" really means; the term itself and its possible uses are a little bit equivocal.

2. secondly, you mentioned the IDE using callbacks in various libraries, but it might be useful to add a section showing how to actually do that.

I recently "tried" to use a 3rd party library that had such a callback function. Unfortunately the library is riddled with bugs, and appeared to never have worked at all [as also evidenced by having ZERO examples included]. However, the callback function code does seem to work ok. I'm including the entire functions below, but it's easy to abstract out the pertinent details. The really nice thing here is, you can write your own callback fcn in your sketch to take the data that is being received in the library as multiple successive packets [upwards to 100s] and store it to any place you want, packet receipt by packet receipt. In this case, it goes onto an SD Card, but could go into a RAM buffer, EEPROM, out another port, etc. All in all, I thought the entire process was pretty darn cool, even if the library was hash.

Code:
----------------------------------------
1. in the program, the callback fcn writes the data in holdBuff to the SD card.
   holdBuff is filled by the library fcn.

/* Each call to _callback() in the library functions will transfer one
   data packet from the temporary holding buffer [holdBuff] and append
     to the SD file until entire image [of picSize bytes] has been
     transferred.
 
  params: ALL params are values to be filled in by call to _callback().
      holdBuff = points to holding buffer containing current image block.
        picStartPos not used here.
************************************************************************/
void sdPic_callback( uint32_t picSize, uint32_t picStartPos,
  uint16_t dataSize, byte* holdBuff )
{
  sdFile.write(holdBuff, dataSize);
  writtenPicSize += dataSize;
 
  Serial.print("\n>SD picture write ");
  if( writtenPicSize >= picSize) {
    sdFile.flush();
    sdFile.close();
    Serial.println("... Success");
  }
  else {  Serial.println("... FAILURE");  }
}

-------------------------------
2. in the program, this is where it calls the library fcn; it passes a pointer
    to [ie the address of] the callback fcn here.

  // transfer picture into SD card.
  if( cam.getJPEGPicture(PT_JPEG,procDelay,&sdPic_callback) )
    Serial.println(">get JPEG Picture ok");
  else  return;

--------------------------------
3. in the library, this is where it calls the callback fcn; it uses a pointer
    to a callback fcn as an input parameter.

The big advantage here is that this fcn has a big loop that grabs N
data packets from the jpeg camera, and uses the callback fcn from
the main program to write the data to the SD card [or anywhere
else that you want to write it]. Alternatively, without the callback
you'd have to code this loop yourself out in the main program.

/*
******************************************************/
bool CameraC328R::getJPEGPictureData( uint32_t picSize, uint16_t processDelay,
   void (*callback)(uint32_t picsize, uint32_t picstartpos,
           uint16_t datalen, byte* holdbuff) )
{
  // vars used locally.
  uint8_t  errCount=0;     // keeps track of #errors, up to MAX_ERRORS.
  uint32_t picDataPos=0;   // current byte position in ENTIRE image.
  bool packSuccess;
   
    // vars passed back to callback().
  uint16_t dataSize=0;          // size of picture data within the package.   
  byte holdBuff[_packageSize];  // holding buffer for camera data, 64(typ).
  uint16_t packCount=0;         // keeps track of #packages received.

  // track errors during data transfer.
  while( (picDataPos < picSize) && (errCount < MAX_ERRORS) ) {
    sendACK(0, packCount);
    delay( PACKAGE_DELAY );   // allow time to process, transmit data

    // wait for the next package from the camera.
    packSuccess=waitForData(processDelay, holdBuff, _packageSize);

    if( packSuccess ) {
      // this is the size of the picture data within the package
      dataSize  = (holdBuff[3] << 8) + holdBuff[2];

      // execute callback
      callback( picSize, picDataPos, dataSize, (holdBuff+PAC_DATA_START) );
     
      picDataPos += dataSize;  // advantage index in image.
      packCount++;
    }
    else {  errCount++;  }
  }
  sendACK(0, LAST_JPEG_ACK);    // send last ACK.

  if( errCount < MAX_ERRORS)  return true;
    else  return false;
}
7  Using Arduino / Programming Questions / Re: Interact Arduino Hardware with C# Program on: September 24, 2014, 11:33:15 pm
If you still want to try making a C# terminal to connect to the Arduino [exclusive of camera], there are a bunch available. The one I had tried seems to no longer be online.

http://www.google.com/custom?q=c%23+terminal&sa=Google+Search&sitesearch=
8  Using Arduino / Programming Questions / Re: accessing a variable in wiring.c on: September 24, 2014, 11:20:32 pm
The extern "C"{} business doesn't work either. I'll try your sketch from the other thread tomorrow to see how it goes. It's gotta be something simple. Thanks.
9  Using Arduino / Programming Questions / Re: Interact Arduino Hardware with C# Program on: September 24, 2014, 10:47:10 pm
james, for reference, which camera were you wanting to interface to the Arduino?

You may be past this point in the discussion by now, but you can interface your arduino to a PC using the serial port object in C#. It's been several years since I tried doing that, but there were some online examples for writing serial routines using C#.
10  Using Arduino / Programming Questions / Re: accessing a variable in wiring.c on: September 24, 2014, 10:41:41 pm
Thanks gardner, I always use verbose compile mode, and had already tried deleting all of the temp directories. I just tried again for good measure, and it still doesn't work. Exit IDE, delete all \temp_dirs, save changes to wiring.c,etc, reopen IDE&sketch, but it still shows 'undefined reference' to the variables, which I assume means fails at the link stage. So still boggled ???

Besides this, I've also wanted to create new functions in wiring.c to call from my sketches. So, I tried creating the functions, and added prototypes to Arduinio.h, just like as done for millis(), etc, but this also doesn't work. The sketch cannot find the functions. So ???

For reference, my basic plan for all this was to hack into ISR(TIMER0_OVF_vect), and make some minor changes [ie, use to modify the above mentioned variables], and then access the variables from my sketches. I did find that the changes in the ISR are made ok, by [temporarily] rewriting the existing micros() function to return the values, but I cannot figure out how to directly reference the variables or the new functions themselves. Has to be something simple that I'm missing.
11  Using Arduino / Programming Questions / accessing a variable in wiring.c on: September 24, 2014, 06:32:05 pm
I have a more complicated problem, but will start simple here. Down in wiring.c, the following variable is defined:
Code:
volatile unsigned long timer0_millis = 0;
and is directly accessible in a sketch, for instance:
Code:
-- in my sketch:
extern volatile unsigned long timer0_millis;

void loop()
{
    Serial.println( timer0_millis );
    delay(2000);   
}
I could not find any other extern references to timer0_millis, say in Arduino.h where the prototype for millis() is located. Is there somewhere else I need to look?

What I am wanting to do is define another variable for my own use in wiring.c, and which will be modified inside ISR(TIMER0_OVF_vect). However, if I treat my variable the same way that timer0_millis is treated, the linker cannot find it when I compile the sketch. What am I missing here? IE,
Code:
-- added to wiring.c:
volatile unsigned long eCnt=0;

-- in my sketch:
extern volatile unsigned long eCnt;

void loop()
{
    Serial.println( eCnt );
    delay(2000);   
}
12  Using Arduino / Microcontrollers / Re: Bricked?? on: August 20, 2014, 05:33:49 am
The bottom of this page has info for different versions of the board. Apparently there are several different ones, so you need to make the right selection.

https://github.com/openLRSng/openLRSng

Have you tried posting to the forum over there? This is a bit outside the normal arduino stuff.

13  Using Arduino / Microcontrollers / Re: New optiboot; beta testers welcome... on: August 14, 2014, 12:52:59 pm
Thanks for clarifying.
14  Using Arduino / Microcontrollers / Re: 328P and NRF24L01+ not running off a coin cell on: August 14, 2014, 11:32:37 am
Quote from: fungus link=topic=260774.msg1842247#msg1842247
Pretty graphs, and simple formulas, :-)
15  Using Arduino / Installation & Troubleshooting / Re: ADDING TO YOUR LIBRARY on: August 14, 2014, 11:16:36 am
What they are referring to is a \library subfolder in your 'sketches' directory, and not the one in the IDE directory. This way your additional libraries will still be present when you update the IDE in the future.
Pages: [1] 2 3 ... 196