I would like to remotely reprogram my Arduino via Android over Bluetooth SPP. The first step is to reset the ATMEGA microcontroller. This is accomplished on the Arduino by toggling the DTR line. Is there any API to control the Bluetooth SPP control lines from the Android environment?
Also it is supported by SPP in general to send or receive the control signals (DTR, DSR, RTS, CTS) I do not know any API or library for android right know, but as you just want to reset your controller...
If it is o.k. for you to change your firmware you can also create your own reset-command that can be received on your UART (over SPP).
If you receive that command you could call something like
asm("jmp 0x3800");
where you have to modify the jmp-address to point to your bootloader.
You also might want to change your interrupt vector to point to your bootloader.
Or enable your watchdog and call
while(1);
This will also automatically change the interrupt vector to the bootloader's interrupt vector and reset all SFRs. - But it is a little bit slower and the bootloader's interrupt vector must be choosen in the Fuse Bits.
I realise that this is not what you wanted, but you could always flash a new bootloader with a longer timeout and manually press the reset button before starting programming.
The new Arduino bootloader (optiboot) fits in 512B (versus the 2K of the old one) so you have extra space available to your projects; has smart boot detection, so it only enters the bootloader when the reset button is pressed; and you can extend the timeout by editing the watchdog timeout value in the source (around line 267 in optiboot.c).
// Set up watchdog to trigger after 500ms (changed to 2s!)
watchdogConfig(WATCHDOG_2S);
Related
I'm a beginner in this field. I have developed an android app through which I can control the LED's connected to the GPIO pins of ESP Wi-Fi module. That app is connected to Firebase to save the status of the buttons. Everything works fine.
Now I want to implement the followings:
I want, if I manually switch off the LED by removing the GPIO pin of respective LED, that status "LED OFF" should be updated on my app.
I want to add Fan speed controller
For first bullet point, should I use firebase too?
Please suggest the tutorial and ways I can achieve both.
Number 1:
Reading digital output states on an ESP8266
You cannot read and write the same pin without blinking the light as you alter pinMode on the fly. The easiest way is to connect another GPIO as the cathode of the LED, and set that pin's pinMode to INPUT. you can then digitalRead that input to determine if the LED is present and on (1) or not (0).
That only works well on red low-power LEDs though, since the GPIOs only handle 12ma officially. You'll likely want to use something like NPN transistors to deliver VCC to them, in which case you can connect the input pin to the LED anode via a 5-10k resistor, and the LED cathode to GND.
In terms of pushing that status to the update, you can poll every few hundred ms, checking that each read value one is the same as the last, and sending the change off to sparkfun when found. Store the state in a global and compare to the read.
You can also use an interrupt instead of polling. These are more performant and complicated, so for very low-frequency events like LED status, polling suffices and is arguably easier to code from scratch. Do look into interrupts eventually though, they are powerful on single-threaded devices.
Number 2:
Controlling fan speed with an ESP8266
You need a PWM circuit to control a DC motor's fan speed. There's many relatively simple circuits using mosfets to connect and disconnect the ground of the fan very quickly, thus averaging its used power as a ratio of maximum power. The ratio is set using analogWrite with a pin # and a int from 0 to 1024.
Note that your fan probably won't spin if the written value is less than 350; there's not enough voltage at those low values. Also, i'd recommended boosting the PWM frequency to super-sonic levels using analogWriteFreq(16000); in setup() to avoid fan noise. If you can get a 12v DC 4-wire PC cooling fan, you can actually hook the pwm input line to the control GPIO and not have to wire any circuits.
If your fan runs on AC, it's a lot more complicated and dangerous. The simplest circuits use an IGBT transistor to achieve "PWM" on an AC signal, but triacs+diacs, and random-cross solid state relays work well if you manage your own cross timing. Make sure you handle motor impedance as well. Complicated? you bet.
I have found that it's easer and cheaper to modify an existing and cheap fan controller like this one, de-soldering the large potentiometer and replacing with an LDR. The pot's used as a variable resistor, not a voltage divider, so it's easy to mimic. You can then tape an LED to the LDR, hook the LED to a GPIO output, and then use analogWrite() to control the AC output. Experiment with LED resistor values to maximize precision and linearity, though for a fan, even just three usable levels would be an improvement. The opto-isolation from the ESP to main is a nice feature of this cheap method.
If you have an existing commercial multi-speed fan with a few levels, like a ceiling fan or a box fan, you can replace the fan's switch/knob with relays to mimic a human selecting a switch position. You have to reverse-engineer which wires are "hot or not" under the different selections. It's mains AC, so do be careful doing that...
I have installed Android 4.2.2 on a ARM board, Orange Pi (A20). I have also an accelerometer based on Arduino Nano (ATMega328) to communicate with the system, via serial USB (UART).
Is a chance exist (with some work!) to make this accelerometer active to rotate the screen, and better, to play with ?
I managed to receive some datas.
1) Build cp210x.ko in the kernel, and insmod it in Android
2) With the Arduino application on Ubuntu, I have programed the chip with the example "MPU6050_raw" (from here) and adding a delay (and incidentally a sensor value)
If the delay is not set, the Orange freeze. It's the begining of my tests..
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(2000); // delay in between reads for stability
}
3) On Android, with the app SerialPort_1.1.apk, set the device /dev/ttyUSB0 and the baudrate to 38400.
Here is the result:
This is a start, now I think the most difficult will be to create my app to treat theses datas...
I am transplanting android to my stb, and I want stb could support touchscreen.
the touchscreen connecte to stb with a serial cable
I am trying to support it in native layer, but I don't know how to do.
I have tryed the following method: using "process" function in inputread.h, but inputreader is not singleton, I can't get it's pointer or refrence.
what should I do?
This is a tough task.
First, you must well know the details of how a touch event is processed. To understand a standard touch event format typically in /dev/input/xxx.
Second, you need to figure out how your current serial touch panel works, what is the out put format of this device.
If your tty device output the same format of a standard touch event, you can simply configure the HAL to open the specific device and all will be settled.
Else, if it is not a standard touch event format, two options for you:
1. Adapt to this format in event hub layer
2. Transform this format in driver layer
Both are not very easy.
I have a Duemilanove and ADK and I followed this and with the exception of some SDK updates, I followed it exactly.
Problem: the onboard LED doesn't blink but is always on.
Issues:
byte array is being successfully sent to the ADK from the phone, verified by monitoring serial port of arduino board
High & low signal is being properly handled in the arduino code (same verification).
the blink tutorial without the ADK blinks the on board LED properly.
So, what is wrong? Is it possible that the ADK board is always sending a HIGH signal to the on board LED and I need to use an 'external' LED for testing? A lot of the tutorials I've seen do this so could that be why?
Try to write a small blink program, just to check that everything is alright in your ADK board.
The onboard Arduino LED is on initially. It looks like it is never being turned off.
In the linked instructions, under the section How To Receive Data From The Android Device , the first line of the loop() function is:
byte msg[0];
Then to receieve data in the call to AndroidAccessory.read() the value sizeof(msg) is used to determine how many bytes to read.
However, because msg was defined to be 0 bytes long, no bytes will be read, len will be zero and the LED will not be updated.
Instead, try changing the line to:
byte msg[1];
I haven't used the shield you are using but it looks like it uses SPI for communication. SPI uses pin 13 for the serial clock signal (SCK). Given this I would expect the SCK signal may be interfering with you trying to control the LED.
I would suggest trying to wire an LED to a different digital pin such as pin 8 and update the Arduino sketch to use pin 8. This would remove the possibility of conflict.
I'm working on a research project which involves Bluetooth and the Android OS. I need to make Bluetooth discoverable indefinitely in order for the project to continue.
The Problem:
Android limits discoverability to 300 seconds.
I cannot ask the user every 300 seconds to turn discoverability back on as my application is designed to run in the background without disturbing the user.
As far as I am aware, there is no way to increase the time though Android's GUI. Some sources have called this a safety feature, others have called this a bug. There may be a bit of truth in both...
What I'm Trying / Have Tried:
I'm trying to edit a stable release of cyanogenmod to turn the discoverability timer off (it's possible; there's a configuration file that needs to have a single number changed). This isn't working because I'm having verification problems with the resulting package.
During the past week, I downloaded the cyanogenmod source code, changed a relevant class in the hope that it would make Bluetooth discoverable indefinitely, and tried to recompile. This did not work because (a) the repo is frequently changed, leading to an unstable code base which fails to compile (OR, it could be that I'm using it incorrectly; just because it looked like it was the code's fault in many instances doesn't mean I should blame it for all the problems I encountered!) and (b) the repo decides to periodically "ignore" me (but not always, as I have gotten the code base before!), replying to my synchronization/connection attempts with:
fatal: The remote end hung up unexpectedly
As you might imagine, the above two issues are problematic and very frustrating to deal with.
More Info:
I'm running Android 2.1 via cyanogenmod (v5 I believe). This means the phone is also rooted.
I have a developer phone, which means that the bootloader is unlocked.
My phone is an HTC Magic (32B).
The Big Question:
How can I make Bluetooth indefinitely discoverable on Android?
See the following link:
http://developer.android.com/guide/topics/wireless/bluetooth.html#ConnectingDevices
Specifically, the last sentence in the paragraph below:
Enabling discoverability
If you would like to make the local device discoverable to other devices, call startActivityForResult(Intent, int) with the ACTION_REQUEST_DISCOVERABLE action Intent. This will issue a request to enable discoverable mode through the system settings (without stopping your application). By default, the device will become discoverable for 120 seconds. You can define a different duration by adding the EXTRA_DISCOVERABLE_DURATION Intent extra. The maximum duration an app can set is 3600 seconds, and a value of 0 means the device is always discoverable.
So, this should work:
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
startActivity(discoverableIntent);
If you check out the BluetoothAdapter class
you will find the hidden method:
public void setDiscoverableTimeout(int timeout)
Now you only have to find out how to use it. You have to do a method invocation to do so.