Show Posts
|
|
Pages: 1 [2] 3 4 ... 16
|
|
16
|
Using Arduino / Programming Questions / Re: How to pass variable to library?
|
on: May 08, 2013, 09:29:07 am
|
It doesn't really matter what's inside .cpp or .h file, I'm just looking for theoretical example how to pass variable between sketch and library without passing it as function argument  Here's an example of simple tutorial LED13 library: LED13.h #ifndef LED13_H #define LED13_H
#include "Arduino.h"
class LED13 { public: LED13(); ~LED13(); void on(); void off(); void blink(int time); };
#endif LED13.cpp #include "LED13.h" //include the declaration for this class
const byte LED_PIN = 13; //use the LED @ Arduino pin 13
//<<constructor>> setup the LED, make pin 13 an OUTPUT LED13::LED13(){ pinMode(LED_PIN, OUTPUT); //make that pin an OUTPUT }
//<<destructor>> LED13::~LED13(){/*nothing to destruct*/}
//turn the LED on void LED13::on(){ digitalWrite(LED_PIN,HIGH); //set the pin HIGH and thus turn LED on }
//turn the LED off void LED13::off(){ digitalWrite(LED_PIN,LOW); //set the pin LOW and thus turn LED off }
//blink the LED in a period equal to paramterer -time. void LED13::blink(int time){ on(); //turn LED on delay(time/2); //wait half of the wanted period off(); //turn LED off delay(time/2); //wait the last half of the wanted period } So in the above example, can someone show me how to declare a variable so I can change it's value in the main sketch and library will see that it changed?
|
|
|
|
|
17
|
Using Arduino / Programming Questions / Re: How to pass variable to library?
|
on: May 08, 2013, 08:46:41 am
|
Ok I'll try it another way  Here's Sketch "A.ino" #include <B.h> void setup() { Serial.begin (115200); } void loop() { if (myVar) Serial.println ("True!") } How would I declare "myVar" in B.h/B.cpp so I can access it from "A.ino"? I've tried declaring myVar in B.h,and in B.cpp (as bool myVar;) but I still get error "myVar not declared" 
|
|
|
|
|
18
|
Using Arduino / Programming Questions / Re: How to pass variable to library?
|
on: May 08, 2013, 07:42:38 am
|
The library can't see your sketch's globals. That's why you get the error.
You can add a global to the library, which then your function can see.
Or you could add an additional argument to a library function and pass the boolean in that way.
-br
Thank you. Could you give me an example of how to define global var in library and then address it from the sketch? I added in the .cpp file: uint8_t myVar; but when I try to assign value to myVar from sketch it tells me "myVar" was no declared in this scope. I do have #include in the beginning...
|
|
|
|
|
19
|
Using Arduino / Programming Questions / How to pass variable to library?
|
on: May 08, 2013, 06:46:45 am
|
I'm trying to modify existing library (RF12B) and send to it a variable (boolean) from my sketch. As a simple example, let's say I have boolean myVar=true; In the library .cpp file I add: if (myVar) Serial.prinln "True"; But I get error: RFM12B.cpp:22: error: 'myVar' was not declared in this scope So how can I pass it to the library's function?
|
|
|
|
|
20
|
Using Arduino / Motors, Mechanics, and Power / Re: Most silent motor out there
|
on: May 07, 2013, 01:49:17 pm
|
Smaller motors are quieter, especially if the case has no ventilation holes. There are some nice micrometal gearmotors on eBay that are about 15mm across and various voltages and gear ratios.
For lower speeds/powers computer case and CPU fans have a brushless motor that's very quiet - you'd have to find an old one and cut off the fan blades and housing.
Thank you! That's a good idea about fan motors! I have some from old videocard 
|
|
|
|
|
21
|
Using Arduino / Microcontrollers / Re: ATMega1284p issues with SD Card
|
on: May 07, 2013, 06:03:52 am
|
Just soldered 10K resistor between CS (hex buffer pin going to RF12B) and +5V line. And everything works without having to do anything in the code at all!  Uploaded unmodified example sketch from SDFat: works! Sketch from WaveShield: it talks!  Receiver sketch for RF12B: receives! Haven't tried both at the same time yet  Thank you again!
|
|
|
|
|
22
|
Using Arduino / Microcontrollers / Re: ATMega1284p issues with SD Card
|
on: May 06, 2013, 08:50:40 pm
|
If both devices are using the same SPI port, then you obviously need to hold their CS pins HIGH when not accessing.
GENIUS!!!! Thank you thank you thank you!!! That was it  I didn't know I have to hold unused port HIGH! As soon as I added this to the setup of the SD Card test sketch: pinMode(18,OUTPUT); // Set Output for RF12B SPI SS digitalWrite (18,HIGH); // Set RF12B SPI SS high It immediately started to list files on the SD card!!!  I think I understand now why Wave Shild had pullup resistor on SS line... I'm pretty sure I need to add one to RF12B so I don't have to pull it high from the code, right?
|
|
|
|
|
24
|
Using Arduino / Microcontrollers / Re: ATMega1284p issues with SD Card
|
on: May 06, 2013, 03:12:28 pm
|
Good, that's a step in the right direction from jeelib, I think. I've heard of the lowpower RFM12 library, but not used it.
Your sketch doesn't show specifically how your library code is using the SPI port, but I imagine that's where the problem is. IE, proper control of the SS and CS pins between the RFM12 and the SD card. And as noted before, the SS pin always has to be configured as output, whether it's used or not.
Also, of course, RFM12 comms will not work properly unless an interrupt is used, so that needs be treated properly in the RFM12 code too.
EDIT: I assume you also assign different node IDs to the 2 different modules, meaning modify the sketch between Arduino boards.
Correct, I'm using totally different sketch for transmitter (attaching if you interested). You gave a good idea about setting SS as high, that could be the issue. So I need to set that port to high (i.e. DigitalWrite(SS_PIN,HIGH) in order to start using it? But let's forget for a minute RF12B. I'm trying an SD card code only (i.e. quickstart sketch from SDFat library) and it just doesn't work... So even if I'm not invoking RF12b in any way in the code it somehow still interferes on hardware level? ..what about the SPI speed?? It could happen the SDdriver sets it to a freq RFM does not like and vice versa..based on the board variant..
Again even when I'm totally ignore RF12b module in software (not including libraries, etc), why wouldn't SD card still work? I'm thinking for adding pullup resistor to RF12b just in case and if that doesn't work I'll solder another board and not attach RF12b components to it, just SD card parts and see if it helps... BTW I really appreciate you guys trying to help me! At least I have some hope now 
|
|
|
|
|
25
|
Using Arduino / Motors, Mechanics, and Power / Most silent motor out there
|
on: May 06, 2013, 01:47:42 pm
|
I'm on a quest to make a small electric toy for my cats that will just run/crawl around the house. I've went thru tons of similar toys form Radioshack, etc. and they all have one big problem. Motors in them is freakishly noisy, even in tiny toys size of thumb. It scares cats. Is there a small low power motor that's almost totally silent? Can you recommend me one?  Not sure if best would be stepper, geared or servo...
|
|
|
|
|
26
|
Using Arduino / Microcontrollers / Re: ATMega1284p issues with SD Card
|
on: May 06, 2013, 01:01:29 pm
|
bratan, getting back to the original problem, have you ever gotten the RFM12s to work with any Arduino chip at all? Also, which library and sketches are you using? If you're using the jeelib s.w., from my experience, none of the sketches work correctly, including the demo sketch. I only ever got the RFM12s to work by using the sketches shown in the Arduino Cookbook.
Yes in fact I only got it working using ATMega1284 running "Mighty 1284p 16Mhz w/ Optiboot". I ran it as a reciever, sketch is below (it uses Felix's RFM12B library which is derivative of Jeelib's but much better). I modified library slightly to include 1284p pin definition, because it only had 644p. // Simple serial pass through program // It initializes the RFM12B radio with optional encryption and passes through any valid messages to the serial port // felix@lowpowerlab.com
#include <RFM12B.h>
// You will need to initialize the radio by telling it what ID it has and what network it's on // The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes) // The Network ID takes values from 0-255 // By default the SPI-SS line used is D10 on Atmega328. You can change it by calling .SetCS(pin) where pin can be {8,9,10} #define NODEID 1 //network ID used for this unit #define NETWORKID 1 //the network ID we are on #define SERIAL_BAUD 115200
#define LED_ID 23 // Pin for LED indicator //encryption is OPTIONAL
// Need an instance of the Radio Module RFM12B radio; void setup() { Serial.begin(SERIAL_BAUD); pinMode(LED_ID, OUTPUT); // Turn on LED port for output Serial.println ("Initializing Radio"); radio.Initialize(NODEID, RF12_915MHZ, NETWORKID); // radio.Encrypt(KEY); //comment this out to disable encryption Serial.println("Listening..."); }
void loop() { if (radio.ReceiveComplete()) { digitalWrite(LED_ID,HIGH); // Turn on LED if (radio.CRCPass()) { Serial.print('[');Serial.print(radio.GetSender());Serial.print("] "); for (byte i = 0; i < *radio.DataLen; i++) //can also use radio.GetDataLen() if you don't like pointers Serial.print((char)radio.Data[i]);
if (radio.ACKRequested()) { radio.SendACK(); Serial.print(" - ACK sent"); } } else Serial.print("BAD-CRC"); Serial.println(); delay (10); digitalWrite(LED_ID,LOW); // Turn of LED } } I have Moteino setup as trasmitter and it's hooked up to DS18B20 temp sensor (on breadboard) and transmits temperature readings. Setup works like a charm. But as I said with Mighty 1284p boot SD card stops working. With Sanguino SD card works but RF12B doesn't work...
|
|
|
|
|
27
|
Using Arduino / Microcontrollers / Re: ATMega1284p issues with SD Card
|
on: May 06, 2013, 07:11:45 am
|
What does this have to do with Bobuino? Nothing that I can see. I request you take Bobuino out of the title.
Hmm ok I removed it. But question was relevant and about Bobuino as well as other variants of 1284p bootloaders, and why they don't work with SD card while Sanguino version did on my version of hardware... Was hoping to get some hints, this was not meant to critique your variant 
|
|
|
|
|
28
|
Using Arduino / Microcontrollers / Re: ATMega1284p issues with SD Card
|
on: May 05, 2013, 10:55:36 pm
|
To OP, I think your ckt is ok, as is. The problem may be that, when you use the SPI peripheral with -CS other than the standard SS pin, you still need to set the SS pin = OUTPUT, else the peripheral will revert to slave mode.
Thanks, I will keep looking for a solution. It's very helpful to at least eliminate hardware as source of the issue  As to SD card voltage (to the person who hijacked my thread  , I'm not an expert but from what I've learned in the past year, every circuit I've seen uses 3.3V for regular SD cards, no exceptions... And from posted specs in voltage range of 2.7 - 3.6V, 3.3V seems like a sweet spot 
|
|
|
|
|
29
|
Using Arduino / Microcontrollers / Re: ATMega1284p issues with SD Card
|
on: May 05, 2013, 11:59:02 am
|
..have a look on the pin definitions in "pins_aruino.h" and do check the stuff around: .. static const uint8_t SS = 4; static const uint8_t MOSI = 5; static const uint8_t MISO = 6; static const uint8_t SCK = 7; .. Tried changing it, but no difference. In fact I'm surprised that SS is defined like that, it can be any pin... BTW speaking of powering whole thing at 3.3V I realized that my DC1307 chip requires 5V. Do you know if it will operate with 3.3V logic if I connect it to 5V VCC?
|
|
|
|
|
30
|
Using Arduino / Microcontrollers / Re: ATMega1284p issues with SD Card
|
on: May 05, 2013, 10:52:29 am
|
..I would not mess with those HC125 drivers as the 1284p runs fine at 3.3V/16MHz..
Hmm, that's true... I guess I can redesign the board, since I already have 3V reg. I only need 5V to drive LED matrix... Thanks. P.S. It seems issue with pin definitions somehow... I tried these bootloaders on same 1284p chip and here's result: - Mighty 1284 w/ Optiboot: RF12B Module works. SD card doesn't work
- Bobuino: RF12B Module Doesn't work (I know I stated in my OP that it worked, but I was wrong). SD Card Doesn't work
- Sanguino 1284 : RF12B Module doesn't work. SD Card WORKS!
How do I get both working? 
|
|
|
|
|