Show Posts
|
|
Pages: 1 2 [3] 4 5 ... 454
|
|
31
|
Using Arduino / Programming Questions / Re: Wire library not transmitting all data?
|
on: June 16, 2013, 07:22:30 am
|
Not if I put a check for input changes inside the while loop. The whole point is delay pauses everything whereas the other way allows you to multitask. Maybe in this particular instance at this particular time I don't have anything inside that function but that doesn't mean I won't be adding something. But this is wholly irrelevant to my topic.
It may be irrelevant to your question, but the approach you're taking is IMO a very poor one which will lead to complex fragile code. Learn to use a non-blocking approach following the techniques demonstrated in the blink without delay example sketch. This approach makes it easy to control multiple activities independently, both time-based and event-based. Changing to a non-blocking approach requires simple but sweeping changes to the structure of your code and the later you leave it to make that change the more work it will take. I recommend you bite the bullet now.
|
|
|
|
|
33
|
Using Arduino / Programming Questions / Re: java RXTX send strings
|
on: June 16, 2013, 07:06:12 am
|
i get this error in the console: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at TwoWaySerialComm.writetoport(TwoWaySerialComm.java:121)
java rxtx I assume that TwoWaySerialComm.writetoport is the function you posted above. I have to assume that, because you haven't posted the complete code. One of the values you're dereferencing at line 121 is null. Of course I have no idea which line that is, because you haven't posted the complete code. Knowing which line it is, it would be easy enough to add some extra checks to detect when objects are null and tell you. Somebody seeing and understanding the complete code might then be able to work out why the object is null and what the best way is to stop it being null. Unfortunately I can't do any of that, because you haven't posted the complete code.
|
|
|
|
|
34
|
Using Arduino / Programming Questions / Re: expressing a statement most compact method
|
on: June 15, 2013, 07:34:33 pm
|
Are you trying to make this specific statement more compact? bitIndex = bitIndex << 1; //shift bits left
If so, a slightly more compact form would be: bitIndex <<= 1; //shift bits left
If you're trying to make the overall for loop more compact then you could replace it with something like this: for (byte i=0; i<sizeof(pins); i++) { bitWrite(data, i, digitalRead(pins[i])); }
|
|
|
|
|
37
|
Using Arduino / Programming Questions / Re: Encapsulate interrupt ISR within a class
|
on: June 15, 2013, 07:28:15 am
|
|
I think that what you'd need to do is write a plain old conventional interrupt handler function which invoked a static method of your 'timer' class. If you want to notify instances of this class then you'd need to have a scheme for the instances to be registered statically with the class, for example with a static array of pointers or linked list in the class, such that the static method could invoke an instance method for each instance.
The code involved would not be especially difficult, but you'd need to be wary about how long the interrupt handler would take to go through this dispatch mechanism and invoke an unknown number of instance methods doing who-knows-what. Also you would need to deal with any application design issues involved in invoking instance methods within an interrupt - if you're calling out to user code then you need to make it clear that the code needs to be written so that it is safe to be called in an interrupt context. Since you're effectively hiding that interruptness in your timer class, it would be ever so easy to forget that and use it to invoke code that directly or indirectly did unsafe things.
My overall reaction to this approach is that the sort of functional complexity/flexibility which would justify this amount of code is not something that should be done in an interrupt.
|
|
|
|
|
40
|
Using Arduino / Project Guidance / Re: Turning heavy load
|
on: June 15, 2013, 07:13:16 am
|
"that there is play/backlash in the connection to your mechanism" that seems to be the best description. The load is directly attached to the servo.
One way to take out backlash is to apply a small preload. If we could visualise your system, it may be possible to come up with better suggestions.
|
|
|
|
|
42
|
Using Arduino / Programming Questions / Re: Problems with arduino-ethernet library (relating to botanicalls)
|
on: June 14, 2013, 06:44:14 pm
|
Is there a better code solution I should use?
Well, you could use the standard library, which has the advantage of being compatible with the current Arduino IDE. It would require changing that botanicalls code to use the different Ethernet API and without comparing the two I can't say how much effort that would take. Alternatively you could encourage the people who wrote the botanicalls code to bring it up to date with the current Arduino IDE.
|
|
|
|
|
43
|
Using Arduino / Programming Questions / Re: Receiving corrupted SMS messaage on Arduino+SIM900 shield
|
on: June 14, 2013, 06:40:08 pm
|
Although the comment refers to NewSoftSerial, that library has been adopted as the standard SoftwareSerial library. Unless your Arduino installation is very old, I would assume the comment refers to SoftwareSerial. The source for the SoftwareSerial library is in libraries\SoftwareSerial\SoftwareSerial.h under the Arduino installation directory - for example, C:\Program Files\Arduino on Windows, or wherever else you chose to install the IDE. The RX buffer size is defined near the top of the file (line 42 in my copy) and looks like this: #define _SS_MAX_RX_BUFF 64 // RX buffer size It's not common to have to hack the standard libraries like this but there's nothing stopping you if you want to do it - just remember what you changed so you can change it back to standard later.
|
|
|
|
|
44
|
Using Arduino / Programming Questions / Re: Help needed to stop a stepper in home position using interrupt.
|
on: June 14, 2013, 06:32:15 pm
|
|
I see no need for the complexity of interrupts in this application. While the motor is moving, you can simply read the input to find whether the switch has changed.
If you want to use the switch to find a home position during setup, you have to actually move the stepper motor. I'd suggest two loops - one to move it away from the home position until the switch opens, and the other to move it back again until the switch closes. All you need to do is step the motor in the required direction at regular intervals until the switch input indicates that it's time to stop.
|
|
|
|
|