Loading...
  Show Posts
Pages: 1 ... 13 14 [15] 16 17 ... 22
211  Using Arduino / Programming Questions / Re: Passing a value to a function on: July 03, 2011, 12:21:19 am
Thanks MarkT

From what I have tested, doing that limits the data that the function can receive to a Long.

I want to be able to pass any datatype to the function. Is there a 'catch all' variable that can receive any data type, or otherwise something that I can add to the calling line (in the void loop) that will convert anything to a passable variable ?
212  Using Arduino / Programming Questions / Passing a value to a function on: July 02, 2011, 04:44:46 pm
Hi all.

I have a 16x4 LCD and want to add a small function that takes care of the offset problem on the 3rd and 4th lines.

Code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.print("hello, world!");
}

void LCDprint(int Lcol,int Lrow,String & Ltext) {
  if(Lrow > 1){
    Lrow = Lrow - 2; 
    Lcol = Lcol + 16;
  } 
  lcd.setCursor(Lcol, Lrow);
  lcd.print(Ltext);
}

void loop() {
LCDprint(0,1,String(millis()/1000));
LCDprint(0,2,(millis()/500));
LCDprint(0,3,(millis()/250));
}


What I can't find is the correct syntax to use when calling the function : for example the 'string' in : String(millis()/1000) - I assume that there is something that will take any value, text or numeric, and convert it to a string / text type variable ?

Then, in the function itself, what do I need to receive that string : void LCDprint(int Lcol,int Lrow,String & Ltext) {

Any help appreciated. Regards.
213  Using Arduino / General Electronics / Re: switching a transistor ? on: July 01, 2011, 04:27:47 pm
I use RS - I see they also have a UK site : http://uk.rs-online.com/web/
214  Using Arduino / General Electronics / Re: switching a transistor ? on: June 30, 2011, 04:33:51 pm
@DaveO: did you post that to the correct thread?

Yes. It is a drawing I did a few weeks back while learning how to control a transistor with the Arduino, and have the transistor drive an external component ( be it a motor, relay, siren, strobe light, etc )

I just thought the diagram may help the original post understand the wiring better. Is there a fault with it ?
215  Using Arduino / General Electronics / Re: switching a transistor ? on: June 30, 2011, 04:18:25 pm
If I understand CrossRoads correctly, the setup should be as attached diagram. Just change the diagram output pin 4 to your pin 13.

I think ( Gurus please confirm here ) that you should be able to replace the relay in the drawing with your motor, and connect it to the 12v+ instead of the 5v+.

Alternatively, use the relay as shown and replace the "siren & strobe" with your motor.
216  Using Arduino / General Electronics / Re: one led = one resitor, two leds = two resistors and so on? on: June 29, 2011, 03:38:54 pm
for single LEDs I use this :
http://led.linear1.org/1led.wiz

and for multiples, I use :
http://led.linear1.org/led.wiz

hth
217  Using Arduino / Programming Questions / Re: Code for keypads on: June 29, 2011, 11:46:19 am
just a (probably newbee stupid) question, as I have never worked with keypads (or many other components) before, but ..

couldn't you connect a different valued resistor to each key, and connect then all to the same analog input. Shouldn't be too hard to write code to link the different voltages received on the pin to the corresponding key, and would only use 1 input pin on the board.

2c
218  Using Arduino / Interfacing w/ Software on the Computer / Logging data for later download to PC on: June 28, 2011, 11:18:06 am
I have a number of temperature sensors working correctly and to be displayed on an LCD screen.

I would also like to store all the temperature data and download it to a PC at a later time.

My initial thought was to simply store the data in a string variable ( just keep adding to it with a delimiter between records ), and have a button to Serial.print the string to the PC when connected. The software on the PC could then split the data to its required format.

However, I seem to recall somewhere that the Arduino will reset every time I connect the USB cable ( or is that when I open the serial Monitor to the board ), in which case I expect the data stored in my string is going to get wiped out.

So how do I do this : should I look at using a simple SD card & socket wired to the Arduino, and write the data to the SD card. A single button could then be used, after the Serial Monitor connection, to retreive the data from the SD file, and Serial.print to the PC ?

I do not (yet) want to have to lay out more capital on purchasing add-on shields.

Any other suggestions or guidance ?
219  General Category / General Discussion / Re: Examples of commercial use? on: June 25, 2011, 01:52:44 am
I dunno.  If you're going to make more than about 20 units, you're probably designing your own PCB anyway, so you just plunk down an appropriate ATmega chip in an otherwise custom design, and maybe make it "Arduino compatible at the software level."  Then maybe you start to get nervous about the status of LGPL-licensed code in deeply embedded systems, and convert those Arduino library calls to use privately written code, leaving you with not much more "Arduino-like" status beyond a compatible bootloader (if that.)

The thing about Arduino is that it's not really a "big" thing.   It lowers the "barrier to entry" of microprocessors to a whole bunch of people (apparently), but the height of that "barrier" looks a lot lower from the "pro" side of the barrier than it does from the "beginner" side.  If you look at the derisive complaints about Arduino on a forum like AVR-freaks, a lot of them boil down to "there's not much to it; I can't believe that people are unable to program AVRs without such simple crutches!"  And to a significant extent, this is correct.  From a Software or Hardware Engineering perspective, the Arduino is not all that impressive.  (Although from a Computer Science Education perspective, it IS impressive.  Do you know how many projects there have been that were supposed to make "computer programming" more "accessible"?  Do you know how few of them have actually succeeded to an extent similar to Arduino?!)


A very interesting view point indeed, and I tend to agree with you.

But look at the Arduino from my point of view :  I'm a newbee tinkerer (part time coder) , not an experienced electronics expert. I want to tinker with a few magnetic contacts, temperature sensors, drive a few relays and LEDs, etc. Having an Arduino to start from as a base, I can do what I want. But if you said to me I have to assemble a board from a long list of parts, I probably wouldn't try - too much hassle, too many unknowns, out of my field of possibilities (atm), many unknown components and too daunting a project for me to consider.

Give me a few months of getting comfortable with my Arduino, and things will probably change, but right now, if it wasn't for the Arduino, I wouldn't have started to tinker at all.

In my opinion, it is a masterpiece.
220  Using Arduino / Sensors / Re: Lost getting started with Maxim digital thermometer on: June 24, 2011, 01:47:50 am
OK. Looks like the code I pasted into the "quote" box didn't appear as pasted.

Have edited the original reply and moved the code to a "code" box - looks correct now.
221  Using Arduino / Sensors / Re: Lost getting started with Maxim digital thermometer on: June 22, 2011, 01:52:03 am
Also, as you see from the diagram, you can have multiple sensors all on the same input pin.

For each sensor, you need to run the first sample code to get each sensors unique address (with only 1 sensor connected), and add it to the second sample code so your code knows which data coming into the input pin is for which sensor.
222  Using Arduino / Sensors / Re: Lost getting started with Maxim digital thermometer on: June 22, 2011, 01:46:19 am
I had the pin numbers incorrect and have already edited the previous post.

pin 1 goes to Ground
pin 2 goes to input pin and to 4k7. Other side of 4k7 goes to 5v
pin 3 goes to 5v

You will also need to download the libraries from the URL included in the sample code.
.
223  Using Arduino / Sensors / Re: Lost getting started with Maxim digital thermometer on: June 22, 2011, 01:39:41 am
Hi Mike

Here's what you need :

pin 1 goes to Ground
pin 2 goes to input pin and to 4k7. Other side of 4k7 goes to 5v
pin 3 goes to 5v

(edited to show correct pins)

see attached drawing.

Next, you need to get the sensors unique address.

To do this, upload and run the following, which will detect the address and display it in the Serial Monitor :

Code:
// This sketch looks for 1-wire devices and
// prints their addresses (serial number) to
// the UART, in a format that is useful in Arduino sketches
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

#include <OneWire.h>

OneWire  ds(3);  // Connect your 1-wire device to pin 3

void setup(void) {
  Serial.begin(9600);
  discoverOneWireDevices();
}

void discoverOneWireDevices(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
 
  Serial.print("Looking for 1-Wire devices...\n\r");
  while(ds.search(addr)) {
    Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
    for( i = 0; i < 8; i++) {
      Serial.print("0x");
      if (addr[i] < 16) {
        Serial.print('0');
      }
      Serial.print(addr[i], HEX);
      if (i < 7) {
        Serial.print(", ");
      }
    }
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        Serial.print("CRC is not valid!\n");
        return;
    }
  }
  Serial.print("\n\r\n\rThat's it.\r\n");
  ds.reset_search();
  return;
}

void loop(void) {
  // nothing to see here
}

After you get the unique address, copy it from the serial monitor and place it into the following code :

Code:
// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html



//add the unique address to the following line

DeviceAddress insideThermometer = { 0x28, 0xCC, 0xD1, 0xE1, 0x02, 0x00, 0x00, 0xE6 };




//use the next code if you add additional sensors
//DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };
//DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(insideThermometer, 11);
//  sensors.setResolution(outsideThermometer, 10);
//  sensors.setResolution(dogHouseThermometer, 10);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    Serial.print(" F: ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}

void loop(void)
{
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  
  Serial.print("Inside temperature is: ");
  printTemperature(insideThermometer);
  Serial.print("\n\r");
//  Serial.print("Outside temperature is: ");
//  printTemperature(outsideThermometer);
//  Serial.print("\n\r");
//  Serial.print("Dog House temperature is: ");
//  printTemperature(dogHouseThermometer);
//  Serial.print("\n\r\n\r");
}

224  Using Arduino / General Electronics / Re: What resistor to use with Optocoupler ? on: June 21, 2011, 04:05:42 pm
Many Thanks Lefty
225  Using Arduino / General Electronics / What resistor to use with Optocoupler ? on: June 21, 2011, 03:45:20 pm
I am wanting to run a 5vDC circuit with a resistor in series, through the diode side of an optocoupler http://za.rs-online.com/web/search/searchBrowseAction.html?method=searchProducts&searchTerm=7085480&x=0&y=0 and then to a switch connected to Ground.

Closing the switch causes current flow which then activates the optocoupler.

What I can't seem to determine is the value of the resistor.

My supply is 5V and I see a "forward voltage" on the spec sheet of 1.25v ( typical ).  But not knowing the correct terms, I can't find the mA value that I need to calc the resistor size.

Help please.
Pages: 1 ... 13 14 [15] 16 17 ... 22