Show Posts
Pages: 1 ... 52 53 [54] 55 56 ... 120
796  Using Arduino / Programming Questions / Re: moving function map into library on: February 25, 2013, 06:25:28 am
Code:
    typedef struct {
      char *name;
      void (HwClassSerial::*func)(char *);
    } function_map[];
   
    static function_map _function_map;

 static function_map _function_map; is invalid, function_map is declared as an array of 'anonymous structs'. Don't worry about typedefs on structs, they are not necessary for this usage in C++.

What I had does work, here is a working example you can modify.

Sketch file:
Code:
#include "a.h"

void processStatusLine(char * buffer) {
  Serial.println((char*)buffer);
}

void setup()
  {
    Serial.begin( 9600 );
    call_function( "status", "test string" );
    return;
  }

void loop(){ return; }

Header ( a.h )
Code:
struct function_map_type{
  const char *name;
  void (*func)(char *);
};

int call_function(const char *name, char * var);
void processStatusLine(char * buffer);

Source ( a.cpp )
Code:
#include "a.h"
#include "Arduino.h"

static const function_map_type function_map[] = { { "status", processStatusLine }, };

int call_function(const char *name, char * var) {
  int i;
  for (i = 0; i < (sizeof(function_map) / sizeof(function_map[0])); i++) {
    if (!strcmp(function_map[i].name, name) && function_map[i].func) {
      function_map[i].func(var);
      return 0;
    }
  }
  return -1;
}
797  Using Arduino / General Electronics / Re: Arduino(1) PWM into Arduino(2) Analog in on: February 25, 2013, 12:37:40 am
Cheers, always good to be safe.
798  Using Arduino / Programming Questions / Re: moving function map into library on: February 25, 2013, 12:21:37 am
This kind of layout below should work, ( untested ) and function_map is not available outside of the Cpp, if it needs to be usable in the sketch file, you'll need a variable marked extern.

Edit: or you will have to make processStatusLine visible to the cpp, by placing its declaration in the header ( can leave the definition in the sketch )

Header:
Code:
struct function_map_type{
  const char *name;
  void (*func)(char *);
};

int call_function(const char *name, char * var);

Cpp
Code:
#include "Arduino.h"

static const function_map_type function_map[] = { { "status", processStatusLine }, };

int call_function(const char *name, char * var) {
  int i;
  for (i = 0; i < (sizeof(function_map) / sizeof(function_map[0])); i++) {
    if (!strcmp(function_map[i].name, name) && function_map[i].func) {
      function_map[i].func(var);
      return 0;
    }
  }
  return -1;
}
799  Using Arduino / General Electronics / Re: Arduino(1) PWM into Arduino(2) Analog in on: February 25, 2013, 12:11:01 am
Yeah, thats cool, I'm using the max and min values to configure graphs on a tft and play with things like zero crossing calculations.

I plan to use a pot to vary the amplitude if needed, I was just wondering if the connection needs some sort of over current protection.
800  Using Arduino / General Electronics / Arduino(1) PWM into Arduino(2) Analog in on: February 25, 2013, 12:00:08 am
Hi all, just a quick one, I have to produce some frequencies on my Uno to help develop another app on a Mega.
I'm looking around for a simple circuit to connect the Arduino to a headphone jack, but for now PWM will be suitable.

My initial problem is I'm sampling a little mic setup ( freetronics module ) but it has incredible noise on the line, so for testing purposes I want a clean signal.

Is it fine to simply connect the grounds together and wire the Uno PWM pin directly into the analog in pin?
Or is a resistor needed to prevent a short circuit?

Also anybody tried and had good results with any headphone jack circuits, everything I have looked at seems to be a variation of some sort of peak detector, whereas I want raw audio biased for Arduino voltages.
801  Using Arduino / Programming Questions / Re: Help with multiple millis() on: February 24, 2013, 10:53:17 pm
Code:
// Keep track of milliseconds elapsed.
 CurrentTimer = millis();

You don't use this variable anywhere.

Code:
const unsigned long timerRateX = 1000UL;
const unsigned long timerRateY = 1000UL;
const unsigned long timerRateZ = 1000UL;
...
  timerLastX = millis();
  timerLastY = millis();
  timerLastZ = millis();

These variables are pretty much set to the same thing, so.

Code:
if ((millis() - timerLastX) >= timerRateX)
...
if ((millis() - timerLastY) >= timerRateY)
...
if ((millis() - timerLastZ) >= timerRateZ)

These if statements probably do their stuff all on the same loop, or with very little delay between, maybe change the initial timing or try  to use 'else if' statements only match one of the conditions per iteration of loop.
802  Using Arduino / Programming Questions / Re: have a question.. on: February 24, 2013, 10:19:46 pm
The simplest way I guess is using the built in serial functionality. Have a look at the examples and tutorials that are accessible through the IDE.

The dimmer example also has some code for processing in comments ( PC side code ).

From the IDE use 'Open->Communication->Dimmer'
803  Using Arduino / Displays / Re: small tft screen test ? on: February 24, 2013, 02:50:51 pm
The UTFT library has a touch demo I'm pretty sure, or it may be included with the touch library.
Search google for it and you'll find the site which has a library 'UTouch'.

I have never used it with an Uno so I can't really help too much, but the UTFT library has a pdf file with a list of modes to use with different controllers, a few variants of the ILI9325 are in there so  you may have to try a few modes.

804  Products / Arduino Due / Re: New UTFT Libray with Arduino ARM spport on: February 24, 2013, 12:35:12 pm
@cyclegadget, I remember reading about a pen that contained conductive ink. If you can get one, and its good quality, you might be able to draw a line over the top of the resistors.

Or use a loop of wire over each resistor, some people fixed the SD card connection using this method.

If you have the resources, a little breakout that reconfigures the 40pin header to the LCD format would work, then you don't need the shield.
805  Using Arduino / Displays / Re: Sainsmart 3.2 tft shield wont respond on: February 23, 2013, 08:26:03 pm
Hi, I have two different screens, both labelled 'TFT_320QVT' and confirm they both work with the ITDB32S for the HX8347A driver.

And I just tested that code too, it worked fine.

I'm using v1.0 of the shield, I'm pretty sure the changes if any only affect the spi connection for the SD. The screen connections aren't changed.

Flash the board to the bare minimum sketch, and un/re-plug the arduino to turn off the LCD, the Arduino cannot reset the screen properly when you upload.


806  Using Arduino / Programming Questions / Re: Programing a Mrico on: February 23, 2013, 06:46:42 pm
try grabbing version 1.0 of the ide or earlier, they shouldn't have the Leonardo additions. If that fixes the problem, post the compatibility problem maybe in the suggestions forum, or find the link on the download page for the google code link, you can report errors there.

Edit:
Download page: http://arduino.cc/en/Main/Software
Google Code: http://code.google.com/p/arduino/
807  Using Arduino / Programming Questions / Re: using the shift operators on: February 23, 2013, 06:22:46 pm
These are custom defines: GLCD_CTRL_DDR, GLCD_CTRL_PORT

But would correspond to AVR 'Data direction registers' and 'Port registers' respectively.

Essentially, 'GLCD_CTRL_DDR =' is setting the WR, RD, CE, CD pins to output. As the operation is an '=' it implicitly sets the untouched bits to 0 or input.

With respect to the shifts: '(1 << GLCD_WR)', GLCD_WR is a define containing the location of the WR pin on the port ( 0 to 7 )
So the 1 gets shifted GLCD_WR bits to the left.

if GLCD_WR  was 2, the operation looks like this:

1 << 2

so looking at the data in binary:

0000 0001

Move the bits 2 places left:

0000 0100  < bit has moved left, creating the decimal number 4.

This relates to the port registers as they are 8-bits wide, so you can modify multiple pins at once. The shifts put a 1(output, 0 = input) in their respective bits, and the | (or) joins them together.

The next line: 'GLCD_CTRL_PORT |='

sets the same pins to 1 ( high, 0=low ), except this time the |= preserves the untouched bits.

Have a look at port manipulation ( search arduino )
and bit manipulation ( arduino and google c++ documents )



 
808  Using Arduino / Displays / Re: Sainsmart 3.2 tft shield wont respond on: February 23, 2013, 03:18:51 am
I would recommend verifying your screen, I have recently received a sainsmart kit ( off ebay store ) and they provided me with an incorrect screen.

Instead of an SSD1289, I have received what look like another one of my screens which has the driver 'HX8347A' and is marked 'TFT_320QVT'

I just verified it with UTFT,

My SSD1289 screen works with:

Code:
UTFT  Display( ITDB32, 38, 39, 40, 41);

For my screen marked 'TFT_320QVT' I was able to get it working with 'ITDB32S' as the first parameter.

Hope this helps.
809  Using Arduino / Programming Questions / Re: Interchanging HIGH/LOW with true/false on: February 21, 2013, 08:15:16 am
I go one step further with "descriptive names" and define

Code:
const boolean ButtonDown = false; // button connects to GND
...
if(digitalRead(pinButton) == ButtonDown){...}

If I need to change the button to high-side switching, there is only one line of code to change

Thats what enums are great for:

Code:
enum BUTTON_STATE{
  ButtonDown ,
  ButtonUp
};
...
if(digitalRead(pinButton) == ButtonDown){...}
810  Using Arduino / Programming Questions / Re: Programming language advice on: February 21, 2013, 08:07:44 am
If you use something like visual studio, the dialogue editor makes it very easy to get quick c++, c#, vb apps up. If you are comfortable with C++, stick with that as its the Arduino language too.

For your fine tuning of CPU control, the windows api has a load of functions for process/thread control, including what core to run your code on. This is available through many languages.

Pages: 1 ... 52 53 [54] 55 56 ... 120