Show Posts
Pages: [1] 2 3 ... 146
1  Using Arduino / Project Guidance / Re: writing a byte to a processor port on: Today at 02:55:36 am
If all pins are on the same port you can write directly to it and modify all 8 pins at the same time.

The AVR source #defines each port in code, on an uno pins 0-7 are all on port D so I can write a byte to it like this:

Code:
PORTD = 0xFF; //All bits on

Check out this page: http://www.arduino.cc/en/Reference/PortManipulation

A mega is better for this ( if you aren't using one already ) as the Uno port D contains the serial RX/TX pins. A mega has a few 8-bit io ports and you can still use the serial to debug.
2  Using Arduino / Programming Questions / Re: How to include a .h file that is inside of a library's utility folder? on: August 20, 2014, 12:39:01 am
This seemed to work:

Code:
//Get IDE to import library.
#ifdef NEVER_DEFINED
  #include <WiFi.h>
  #include <SPI.h>  //needed because the lib .cpp files are compiled.
#endif

//Include the file.
#include <utility/wl_definitions.h>
3  Using Arduino / Programming Questions / Re: Dumb novice question -- How does one stop a sketch from continuing to run? on: August 19, 2014, 08:06:05 pm
Here is a link to an article I wrote, it explains a few different methods: http://arduino.land/FAQ/content/7/47/en/how-to-stop-an-arduino-sketch.html
4  Using Arduino / Programming Questions / Re: Access a struct passed in the constructor on: August 19, 2014, 03:24:26 am
What would you use a Struct for which you could not use a Class for and why?

Backwards compatibility with C.

Quote
I didn't mention Unions.  There is a whole debate to be had about using Unions at all.

I did , because a union is a class defined with the class-key union. Threw it in to stir the pot, even though one class-key may be able to mimic the other, the advantages of each are distinct.

Really, whats the debate.
5  Using Arduino / Programming Questions / Re: Issue with a very simple library on: August 18, 2014, 04:38:09 am
No, the sketch name does not have to match.

But your code does work as posted. Have you restarted the IDE since creating the library folder: http://arduino.land/FAQ/content/5/19/en/the-library-is-in-the-right-folder-but-it-does-not-work.html

I have attached your code as a single file so you can prove it works, there is a problem elsewhere.


6  Using Arduino / Programming Questions / Re: Issue with a very simple library on: August 18, 2014, 04:15:40 am
I'll take a guess; your libraries are in the wrong spot, or if you use the name sim908_v6 for your .h file, you must name the folder the same.


You obviously do have two different codes regardless of the file name:
Quote
/Applications/sim908_v6.ino:16: undefined reference to `Sim908::blinkLed(int, int, int)'
/Applications/sim908.ino:28: undefined reference to `Sim908::blinkLed(int, int, int)'
7  Using Arduino / Programming Questions / Re: Issue with a very simple library on: August 18, 2014, 04:08:45 am
Did you try the code.

Yes!

Quote
C:\Users\Chris\AppData\Local\Temp\build5652238097145858837.tmp/sim908.cpp.hex

Sketch uses 1,260 bytes (3%) of program storage space. Maximum is 32,256 bytes.
Global variables use 12 bytes (0%) of dynamic memory, leaving 2,036 bytes for local variables. Maximum is 2,048 bytes.
8  Using Arduino / Programming Questions / Re: Issue with a very simple library on: August 18, 2014, 04:03:31 am
Your code compiles fine ( 1.5.6 & 1.5.7 ).

Sure you posted the right file?
The error is for sim908_v6.ino and you posted sim908.ino?
9  Using Arduino / Programming Questions / Re: Access a struct passed in the constructor on: August 18, 2014, 03:03:51 am
Quote
The Class keyword effectively deprecates the Struct keyword.

Not really, structs and unions have their own differences to a class. If you were to open up an old sketch and replace 'struct' with 'class' you will end up breaking your code.
10  Using Arduino / Programming Questions / Re: Doesn't seem to recognize the libraries? on: August 17, 2014, 09:51:33 am
You need to have the libraries included in your sketch ( .ino ), even if it does not directly use it. You can include them elsewhere too ( with the appropriate header guards in place ).

Read the third bullet point: http://arduino.land/FAQ/content/1/3/en/what-does-the-ide-change-in-my-sketch.html
11  Development / Other Software Development / Re: New peek function for HardwareSerial on: August 17, 2014, 08:53:04 am
Here is a solution. And you can access RX and TX buffers. Sorry for any headaches it may cause, and feel free to ask if you have questions.

Code:
template< typename Tag, typename Tag::type M >
  struct AccessMember{
    friend typename Tag::type get( Tag ){ return M; }
};

template< bool _RX >
struct HardwareSerial_Buffer{
  typedef uint8_t arr_t[ _RX ? SERIAL_RX_BUFFER_SIZE : SERIAL_TX_BUFFER_SIZE ];
  typedef arr_t HardwareSerial::*type;
  friend type get( HardwareSerial_Buffer );
};

template struct AccessMember< HardwareSerial_Buffer< true >, &HardwareSerial::_rx_buffer >;
template struct AccessMember< HardwareSerial_Buffer< false >, &HardwareSerial::_tx_buffer >;

uint8_t *GetRX( HardwareSerial &instance ){ return instance.*get( HardwareSerial_Buffer< true >() ); }
uint8_t *GetTX( HardwareSerial &instance ){ return instance.*get( HardwareSerial_Buffer< false >() ); }

And it is used very simply:
Code:
void setup() {
  Serial.begin( 9600 );
  
  uint8_t *rx_start = GetRX( Serial );
  uint8_t *tx_start = GetTX( Serial );
}

void loop() {}
12  Development / Other Software Development / Re: New peek function for HardwareSerial on: August 17, 2014, 08:25:20 am
Sorry,
then the only way seems to be to mod the libs...  smiley-sad

There is always a way. I'll have a crack and see what I can come up with.

13  Using Arduino / Programming Questions / Re: HTML/CSS/Java Webpage w Arduino Mega & Wifi Shield on: August 15, 2014, 02:31:22 am
If you are using external resources, make the most of it. ( googledrive / web hosting )

The Arduino only need send a few lines at most if you can link in a javascript, or iframe resource.

Javascript can control the whole site. Interaction after the initial html page only needs to be ajax requests for data. All the visual elements can be externally loaded.

As for the tediousness of writing the code in client.print calls, C++ allows a few strange things, take this for instance:

Code:
client.print(
    "This is line 1 "
    "This is line 2 "
    "This is line 3 "
    "however, they are all actually "
    "on the same line"
);

Its still produces a single line, but as its HTML, it does not matter. The code possibly looks neater though.

Just remember for plain text, you'll need to add a space to the end of each string or at the start of a new string, Otherwisetheresultcouldlooklikethis.
14  Using Arduino / Programming Questions / Re: Constructor not called and loop not runnin on: August 14, 2014, 09:10:34 am
If you want to use Arduino features in the constructor, just don't use a global object... However there is always a solution.

On an AVR you can control the start up, which I do in my library here: http://arduino.land/Code/SmallSetup/. Using it, your original code should work ( as it calls init() before global constructors are called. ).

The code is short so I'll post it here, you do not need to do anything apart from include it, or just dump this code into the start of your sketch.

Code:
//Written by Christopher Andrews, Provided under MIT & GPL licences.
#if defined( __AVR__ ) && !defined( HEADER_SMALLSETUP )
#define HEADER_SMALLSETUP
#include "wiring.c"

/*** init runs before constructors ***/
__attribute__ ((naked)) __attribute__ ((section (".init5"))) void init();

/*** USBAttach runs after constructors ***/
#if defined( USBCON )
__attribute__ ((naked)) __attribute__ ((section (".init7"))) void USBAttach();
void USBAttach(){ USBDevice.attach(); }
#endif

/*** setup runs after USBAttach to ensure Serial is active ***/
__attribute__ ((naked)) __attribute__ ((section (".init8")))  void setup();

/*** main() runs as normal, only contains runtime code ***/
__attribute__ ((naked)) int main();

#ifdef __AVR_ATtiny25__
int main(){ return (({while( loop(), true );}),0x00); }
#else
int main(){ return (({while( ( serialEventRun ? serialEventRun() : ( void ) 0 ), loop(), true );}),0x00); }
#endif
#endif
15  Using Arduino / Programming Questions / Re: How to pass function / variable name? on: August 14, 2014, 08:56:08 am
Quote
What am I missing?

Nothing, its the IDE's fault.

It generates prototypes. Longs story short add a prototype below the typedef:

Code:
typedef void (*footype)();
void bar(footype g);

void bar(footype g){
  Serial.print("inside bar\n");
  g();
}

This article explains what is happening in detail:
http://arduino.land/FAQ/content/2/13/en/my-class_reference-won_t-work-in-the-sketch.html

Down the bottom I show how to write a function that does not have a prototype generated.
Pages: [1] 2 3 ... 146