Arduino - Trying to keep a pin high, but it's not working - arduino

I'm building a small robot that uses a relay to power the motors. To run the relay, I have it connected to pins 11 and 12. If I use something like the Blink example, where it turns the pin on, then off a second later, it works fine. However, what I'm trying to do is keep a pin on until an IF statement is met. When I run it, it turns the pin on for a millisecond or so, then off permanently. How could I get this to work?

Well, I have a couple guesses, but your description is vague without knowing what the IF statement is...maybe it is being met somehow without your knowledge.
I am pretty certain the light is staying on longer than a millisecond in order for you to see it. As a side note, here is an interesting, related article: http://www.100fps.com/how_many_frames_can_humans_see.htm
Are you debouncing? http://arduino.cc/en/Tutorial/Debounce
I can imagine a simple program with an IF to count button presses -- or the timing of -- where, without debouncing, you will meet the conditional without it seeming correct.
This is just one possibility, but without knowing the code, or the setup it's hard to say.

Related

Cannot clone nRF52840 to reproduce low deep sleep current

I currently have firmware that can reach an average deep sleep current of ~130uA. I can reach this level reproducibly on one of the boards I have.
successful deep sleep
Trouble is, when I try to clone this chip onto other chips using the nRF Programmer (Connect) app, I get extremely high power consumption, average of ~20mA at all times, seems the device doesn't reach deep sleep properly. Tried this on several other boards, so I don't believe it's simply a problem of something shorting. Strangely, the application just runs fine, the current is just several times normal for the same functionality.
unsuccessful deep sleep
Does anyone have any ideas on how I can truly clone the flash of one device, onto another? Clearly the "save as file" on nRF Connect isn't doing this. Erasing all and reuploading, starting from a blank chip and writing,
FYI I'm using the nRF52840 module by Raytac (MDBT50Q), implemented on a custom board. This board SHOULD be capable of going down to ~33uA, which I have observed in the past with this very board. By some combination of erasing all, reprogramming, setting the 3.3V logic level(nrfjprog --memwr 0x10001304 --val 5), etc,
For posterity, I did actually find the solution! For anyone else in a similar boat to me, the winning command is:
nrfjprog.exe --readcode --readuicr --readram [filename.hex]
Apparently, the --readram was the winning flag, as without it the sketch simply doesn't run at the same current consumption for whatever reason. But now, I can reproducibly image and transfer identical firmware, which was what I was after.

How do I make sure the Arduino only run this line of code once even after reset?

I have a real-time Clock module and I'm trying to make an RGB Clock out of it. There is a particular line of code that sets the time and date to the real-time clock module. I put this in the setup code but every time I reset the Arduino it runs that line of code again. Is there any way that I can make sure that once this line in of code is run it will never run again even if I reset the Arduino?
It is a broad question which goes beyond programming. The answer to your concrete problem is "Remove that line of code" from setup, it will not run (I am sure you know this). However, you should provide some physical input (buttons + rudimentary menu-like interface) to set the clock on first usage. A second way of setting the time can be a serial port to which you can physically connect. This requires some code to read that serial port in your loop method.
In the release version of you Clock firmware I would leave just reading the time stored in EEPROM (from RTC module or an external chip), not the hard-coded value in setup.
Your RTC might have a bit saying "RTC stopped", which you might use to switch to "normal behavior". It will be set when removing power and the RTC-battery. The RTC will probably read "1-Jan-1970 00:00" then, and won't increment unless set.
However, your demo code to set the RTC is just demo code, not intended to really use as is. (See Victor's response for more details)

two identical arduino Nano`s running at different speeds?

I am working on a project that requires me to use 2 separate Arduinos running independently from each other. Now, both of these Arduino's are running the same code, but I noticed that after 10 minutes or so, one of them falls behind and this time difference keep increasing with time. Like I already mentioned, the Arduino`s are identical and I bought them at the same time and they are running the same copy of the program. Any ideas what might cause this and how can I fix it?
Thank you.
Here is the link to the Arduino that I bought just in case.
My Arduino modules on Amazon
The Crystal Oszillators have tolerances up to 100ppm (extreme case), which means you could possibly get 16Mhz*100ppm = 1600 clock pulses difference per second. Also the differences of the runtime could be caused by small voltage differences. Even if there is a voltage Regulator on the Board it has small tolerances, based on the fact, that it operates in the Range of MHz this can climb up to an recognizable Offset.
A possible solution is a synchronization of both microcontrollers. I'm not an expert, so the following solution is a possible and easy one, but definitly not the best.
If they are near by each other you can use two pins of each controller. One as Input and one as Output. Write something like this in your code (same for both if you use the same Pins):
digitalWrite(outPin, LOW);
while(digitalRead(inPin)){};
digitalWrite(outPin, HIGH);
Connect the Output from the first to the Input from the second and the same from second to first.
This results in a waiting state for each cycle of the faster Controller until the slower one reaches the same Programm Part. But be careful if one of them stucks somewhere it will stop the second one too. So there is no redundancy! if this was your goal, don't use this method and search for other synchronisation methods.
Perhaps you can use some RTC (real time clock) hardware to help you to keep they synchronised. They are really cheap and easy to use.

SIM5216A phone functionality (CFUN) is not maintained

I'm quite new to working with Arduino/GSM and have had problems getting basic HTTP functionality working. I am currently facing multiple problems - one being that the 3G shield I am working with (SIMCOM SIM5216A) does not seem to want to connect to a carrier! :(
However, the problem I would like to focus on for this question is that Phone Functionality - designated through the AT+CFUN command - does not seem to be maintained through power cycles. Additionally, sometimes after modifying the CFUN, the modem will run a soft reset.
Here is the command I have been using to modify the phone functionality of the modem:
AT+CFUN=1,0
I am under the impression that the second parameter should stop it from running a soft reset.
I have attempted to save the AT configuration by following advice in this question's accepted answer - here is the output from power on:
START
+STIN: 25
+STIN: 25
+CPIN: READY
SMS DONE
PB DONE
AT+CFUN=1,0
OK
AT&W
OK
However, whenever I next reset, I will get the following:
AT+CFUN?
+CFUN: 4
OK
So, my question is how can I save the CFUN configuration to be consistent between power cycles? (If you happen to be able to offer advice on why I can see medium-strength signal but cannot connect to an operator network, any advice would be welcome there too, however that is not the focus of this question)
With thanks,
BadDevH.
Exactly what that is saved with AT&W is a rather muddled, see this answer for details. However, regardless of that, the AT+CFUN command is controlling such a dynamic behaviour that I cannot imagine any manufacturer ever that has saved this with &W. Think more of CFUN more like setting a fixed cruise control speed while driving a car. There is no way the car will continue with the speed from last time when started.
For normal phones the default behaviour is value 1 - full functionality - because that is the very core functionality of what they do1, but for a GSM module shield, I am guessing that the default behaviour is set to no radio in order to save power, so it stays off until you need it at which point you need to explicitly turn it on.
1
And even in the case of no sim card present, it shall still be able to make emergency calls.

How to diagnose VISA/RS-232 communication failure in LabVIEW?

I've been writing a LabVIEW program to drive 3 axis Newport SMC-100 stepper motor controller for horizontal, vertical and rotational movement. I've implemented a for loop that repeatedly perform .3 degree turn followed by 5 separate horizontal movement until it turns a full circle. The program always fails at tellcontrollerstatus.vi, and gives me VISA 1073807339 timeout error. When I restart the program, it'll tell me there is no RS-232 connection available. The weird thing is, it happens at various loop iteration.
I'm sure the COM port setting is correct. If it's a simple program that tells the rotational stage to make a full turn in 1000 steps, it doesn't have any problem. It's only when I try to control two axes in each loop that I have problem.
I tried implementing delay using flat sequence but it doesn't really help. Eventually, I gave up changing the program and just tried another USB-RS-232 adapter cable. Then the problem is gone.
Although the problem was solved, it's not based on good diagnostic procedure and seems to be sheer luck. I'd like to know if there is a proper way to diagnose this kind of problem?
I always use addrcom to diagnose port.
http://www.ontrak.net/adrcom.htm
Also, you can short circuit pin 2 with 3 on DB9 and see weather do you receive the same data you have sent over COM. If you do so it means that your USB-RS-232 adapter cable working properly.

Resources