I made an app in App Inventor that sends text to arduino. Text is of type: "1,1,2,2,0,0,0,2,1,0". But at the arduino end I receive something like this: x€xx€xx€xx€...
For communication i use HC-05 bluetooth module. And arduino is mega adk. I tried to set encoding in App Inventor to UTF-8 and ASCII. Is there a way to this without changing arduino code?
arduino code:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial1.begin(38400);
Serial.println("Starting");
}
void loop() {
if (Serial1.available()>0) {
String data;
data = Serial1.readString();
Serial.println(data);
}
delay(2000);
}
App Inventor blocks (sending):
I don't think it's your encoding. Try changing the baud rate of Serial1 to 9600 as well. (You should configure your Bluetooth module to work at this baud rate too) Also, I suggest you do it this way:
if(Serial1.available()) {
Serial.print((char)Serial1.read());
}
If these didn't work either, make sure your bluetooth is configured properly, devices are paied and connected etc. Also, you may download and use the serial Bluetooth terminals that are already in GoogleStore to make sure you receive the bytes properly first.
Related
I’m trying to send a midi data from a .mid file with AKSequencer(), on a virtual output to use it outside the app (more detail below). My problem is my AKSequencer doesn't send midi outside my app like I would like to do with the virtualOuput port.
// My midiOutput is set like this:
let midiOut = AKMIDI()
midiOut.createVirtualOutputPort()
midiOut.openOutput()
//And my AKSequencer connect to the midiOuput like this:
sequencer.setGlobalMIDIOutput(midiOut.virtualOutput)
I set up an AKSampler() to be sure my AKSequencer work fine.
I think my issue provide either from my connexion to the midiOutput, either my use of AKSequencer not design to send midi like I imagine.
To enter into details, I’m trying to send MIDI over Bluetooth from an iOS app to a DAW. Thank the CABTMIDILocalPeripheralViewController. it’s very easy to set up a connection to send midi when two devices are connected established. I achieve to send midi with AKMIDI().sendNoteOnMessage() so I’m sure the connection is not the problem.
Sending MIDI outside with AKSequencer a bit tricky. You need to either use AKMIDICallbackInstrument or your own AKMIDIListener to get MIDI from the sequencer and reroute outside of your app by AKMIDI output.
There is a discussion on this thread:
https://groups.google.com/forum/#!topic/audiokit/6VkayJMpMvY
Also, you may want to check out my MIDISequencer library built top on AKSequencer with iOS and Mac examples:
https://github.com/cemolcay/MIDISequencer
Ok, so I've never done anything with serial connections before. But...
I just got an Arduino that I am trying to use to remotely launch model rockets. I have a 5 volt relay that I can control with the Arduino's digital out.
Now, I want connect my iPhone's Tx to the Arduino's Rx and vice-versa. I would buy the iPhone breakout board from spark fun so I could connect it to the Arduino. (http://www.sparkfun.com/products/10645) I was thinking something along the lines of: when the phone gets a text or a call from a certain number, or maybe even just a bluetooth signal, it would tell the Arduino. But those are just ideas.
How can I actually send a signal from my iPhone? Are there xCode libraries to do this? My phone is jailbroken, so I am open to other non-apple ways for sending signals. But I am a novice programmer.
Thank you.
P.S. I'm new to Stack Overflow, and I would appreciate if you could help me. The first time I posted a question someone told me it wasn't on the right site. So please bear with me.
EDIT #1: Haha, I just read over this and it sounds like a cell phone bomb from a terrorist movie. I swear that's not what I'm doing. Just look at my avatar.
EDIT #2: I also have a Bluetooth dongle for the Arduino. But I honestly have no idea how to interface that with anything, it was $10 from China, so I thought I would buy it to keep my options open. But, regardless, it would be really cool to plug an iPhone into an Arduino.
You could buy a Redpark Serial Cable for iOS to connect the iPhone to your Arduino board over RS-232.
This book also seems to be helpful: iOS Sensor Apps with Arduino
EDIT:
Redpark FAQ: http://redpark.com/c2db9_FAQs.html
There is a SDK available for this serial cable.
You will have trouble writing communication software when trying to connect directly to the dock connector! The External Accessory Framework wont help you here unless your Arduino board has a special decoding chip for dock connector communication.
Have fun!
All I think you need to do is utilize the External Accessory framework. I'm not sure how well it will work for you, the library is meant to communicate with MFi approved accessories. I'd really like to hear how your results went, I am going to be conducting an experiment of my own using a break out board
I am in a similar boat as you, and I have successfully built my own serial cable using the podbreakout, and have implemented a serial class that supports reading / writing. I can confirm that I have read working, as I have tested it with my RFID reader. I am in the process of writing code that will send a command to the Arduino from the iPhone, and then have the Arduino perform a task based on the command.
Here is a document I put together on iDevice serial com,
https://docs.google.com/document/d/1Yi9_hcw8XSyYNCG2OJT9oHlTG-dC-Dnuc58VIULa81Q/edit?usp=sharing
and the serial class can be seen in the project I am working on.
https://github.com/ipatch/KegCop
Hi looking for some advice. I am writing some music composition software. I have cobbled together tools to read write and send midi data, they work fine. However I stumped on the following: I'm trying to send midi events to a SW synthesizer on the computer.
So I can control the sw synth from an external keyboard. I can control the keyboard from my own sw in the computer. But how do I get my sw to send midi to the sw synth in the same computer.
Also I'm trying to do this in a platform independent way if possible.
Thanks!
VMan
My question wasn't clear.
So I'm currently running on Win7. Cross platform is a priority but not for the first prototype.
Specifically my problem is with accessing kontakt player (v2) it works within it's own environment and with midi IO. But I can't access it from within my own software.
midiOutGetNumDevs returns just one device and it's the Microsoft GS Wavetable Synth.
I'm confused that I can send midi to the kontakt player via a midi/usb cable but that it doesn't show up as a midi device.
What am I missing?
Thx
Which API/OS are you using? Which SoftSynth?
Short answer: you might try "PortMidi".
http://portmedia.sourceforge.net/
Long(er) answer:
I haven't found any cross-platform MIDI lib able to speak to any kind of MIDI sink. In fact it depends on what the softsynth use for receiving MIDI events.
1) On Linux, you can use ALSA to speak to the ALSA synths. A softsynth can register itself as an ALSA sink. You can either:
* use the ALSA lib to connect to send MIDI events to this sink ;
* or you can register your application as a ALSA MIDI source and use another program (aconnectgui, qjackctl, patchage) to connect it to any sink.
http://www.alsa-project.org/alsa-doc/alsa-lib/rawmidi.html
http://www.alsa-project.org/alsa-doc/alsa-lib/seq.html
Downside: Linux specific
2) You can use JACK for MIDI. As in ALSA MIDI, an application can register MIDI sources and sinks. Yhe softsynth can register as a JACK MIDI sink. Then you need to make you app a JACK MIDI source and connect them with another program (qjackctl, patchage).
http://jackaudio.org/files/docs/html/index.html
Downside: need installation, configuration, launching of JACK
You have two solutions to move the ALSA sink/sources as JACK sink/sources :
either use the built-in functionality of JACK (commandline -Xseq) ;
or using "a2jmidi"
4) On MacOS you can do MIDI with CoreAudio. I don't know anything about it though.
5) On windows, I guess you use the midi* functions in
6) Use OSS on some other OSes
7) Communicate with the synth using socket/protocols
You could make your software send MIDI events using MIDI/RTP or MIDI/UDP so you don't care about the driver/OS. Most softsynth don't speak any of those directly so you need a program to do the bridging (qmidinet or others).
8) PortMidi is a cross platform lib for MIDI. However it doesn't seem to be able to use JACK as a backend directly (you can however make the ALSA devices available in JACK as explained above).
http://portmedia.sourceforge.net/
For example, on Linux, Fluidsynth can use ALSA, OSS and JACK for MIDI input. Timidity++ can use ALSA and the Windows API.
OK the answer to this problem is to use a virtual midi driver. I found a free one here:
http://nerds.de/en/loopbe1.html
This creates a midi output device that shows up with midiOutGetNumDevs that I can stream my midi notes too and other Midi software on the same computer can use it as a midi input device.
Works on Win7 and apprently also has mac support. My problem is solved.
"LoopBe1 is an internal MIDI device for transferring MIDI data between computer programs. Basically LoopBe1 is an "invisible cable" to connect a MIDI outport of an application to any other application´s MIDI inport."
Agreed that a Virtual MIDI Driver is the easiest solution.
Another one that used to be very popular (not sure how it performs on Win7 though) is MIDI Yoke. http://www.midiox.com/
If you are looking to do something commercial, you may consider writing your own virtual MIDI driver to make your software controller(sender) a virtual MIDI source. Only on Windows will this be a lot of work.
On Mac and Linux your job is much easier. As #ysdx said, Mac using CoreMIDI and Linux using ALSA/Jack, this is very easy to do in your application by creating a Virtual MIDI port and connecting to destinations.
I have a project where I need my iPhone to communicate with an Arduino. Bluetooth seems like the best option for the communication. How should I program my iPhone (what framework?) to communicate with the Bluetooth Mate or do Apple's restrictions prevent this? Is it possible with a jailbroken iPhone? Is there a better way other than Bluetooth? Sample code would be helpful.
Thanks in advance
Actually you can make it happen now without Jailbreaking or MFi enrollment.
Take a look ate Bluetooth 4.0 in newer iOS devices and Arduino BT 4.0 shield.
This might help: http://blog.makezine.com/2012/03/19/bluetooth-4-0-from-arduino-to-iphone-no-jailbreaking-no-mfi/
Meanwhile there is an Arduino shield available from Seeedstudio: Bluetooth Low Energy Shield
Devices following the Bluetooth 4.0 specification can be accessed by all iPhone/iPad models with a Bluetooth 4.0 chip inside (currently iPhone 4S, 5 and iPad 3) running with iOS 6. You no longer need to be part of the MFI program or jailbreak the device for most purposes. Use the Core Bluetooth Framework that's also discussed in the WWDC 2012 videos Core Bluetooth 101 (Core OS) and Advanced Core Bluetooth (Core OS).
It's been a while since I was in contact with embedded bluetooth-to-iphone devices, but as far as I remember you have to buy authentication chips from apple.
Apple MFi
But as jailbreak is an option this might work. But I never tried this, because I once was in possession of some authentication chips.
I found btstack with a quick googling, maybe it's helpful.
Try instaling bluetoth iBlueNova, and it will comunicate with each device.
Yes, the best way to do this would be to use Blynk. Make an account, copy the example code, and get started with the Blynk app!
Apple's OS app sandbox prevents generic (Classic non-BLE) Bluetooth serial data comm on stock OS devices, except for a few companies registered in their MFi program.
The most reliable and possibly the easiest solution is to the use the Arduino Ethernet shield with a physical network connection to your WiFi router. The Arduino would host web pages or respond directly to http that did your work for you.
No jailbreaking, no BT programming, no serial com port stuff. Just regular old web pages. Sweet stuff.
The simplest solution would be to navigate with any browser on your network, including your iPhone, to your Arduino and issues commands.
Example:
http://192.168.1.101/?1
192.168.1.101 = the IP of your Arduino
?1 would mean PIN13 pulled high (i.e. turn on the LED)
Your code would be something like:
EthernetClient client = server.available();
while (client.connected())
{
if (client.available())
{
char cVar = client.read();
if (cVar != '?') return;
Serial.Print(cVar)
if (cVar == '1') digitalWrite(13, HIGH); //turn on the led
}
}
That code is quick and dirty so don't hold it against me!
Let me know what you decide and how it works out. I need to go read up on http://blog.makezine.com/2012/03/19/bluetooth-4-0-from-arduino-to-iphone-no-jailbreaking-no-mfi/
Thanks for that link ygbr!
I'm having a strange problem when sending UDP packets from an iPhone over a 3G. Almost every time my application starts after a longer period of network inactivity (for instance after the phone comes from the sleep mode or it just gets a 3G connection), my application is not able to send any UDP packets. I get a kCFSocketError error status from CFSocketSendData. The application logic then re-tries to send the packet periodically every five seconds, but no matter how long I let it run it keeps failing. However, when I switch the application to background and open, for instance, a web page in Safari (while the application is still failing on background), the application suddenly starts working. Basically, it seems like the other network activity (from Safari, Maps etc.) "kicks off the networking for real". Do I need to do anything special in terms of network initialisation for instance?
This is a simplified snippet of the code I'm using to send the UDP packets:
CFSocketRef cfSocket = CFSocketCreate(NULL, 0, SOCK_DGRAM, IPPROTO_UDP, kCFSocketNoCallBack, NULL, NULL);
if (!cfSocket)
{
// snip: some error handling
}
struct sockaddr_in addr;
// snip: init addr
CFDataRef cfAddr = CFDataCreate(NULL, (unsigned char *)&addr, sizeof(addr));
CFSocketError sendPacketResult = CFSocketSendData(cfSocket, cfAddr, cfPacketData, 0.0);
if (sendPacketResult != kCFSocketSuccess)
{
// try again in 5 seconds
}
It all works fine without any problems over Wi-Fi.
To be fair, I think I've seen sometimes (but very occasionally) the same behaviour in the standard iPhone applications (Safari, Maps, ...) as well. Sometimes they refuse to connect (even thought I see the 3G icon) and I need to close and reopen them. But it's very rare.
Edit: Possibly related question: On iPhone, what does EPERM (errno == 1) mean in reponse to send() of UDP data?.
The 3G TCP/IP network interface can be torn down by IOS at the operating system's pleasure, generally for power-saving reasons if there is no traffic going across it. When using BSD sockets (for example, for UDP, since there is no UDP apple networking framework) there's no published OS call for ensuring the 3G network interface is up. But internally in Apple's CFSocketStream class there exists private Apple calls that wake up the interface.
So the solution seems to be to open up a CFSocketStream to someplace. That will wake up the interface for some period of time. As long as you send data over the CFSocketStream once a minute or so the connection and the network interface will stay up.
This isn't all that attractive, since it's only working by side effect. But it seems to be the only solution at this point.