Make sounds from photoresistor on arduino using MIDI on garageband? - arduino

I'm having trouble trying to make sounds from my photoresistor using MIDI. I have a MIDISPORT USB. I connected MIDI OUT from my breadboard from the MIDI JACK and my MIDI IN isn't connected to anything because I don't know where it should go or if I should just leave it. I'm using Hairless MIDI serial program to connect my arduino with MIDI, they seem to receiving signal from my usb on the arduino side and the Midi side but I don't hear any sounds.
How does garageband come in to this? It doesn't have to be garageband, i just want to make this work and hear the sounds. I made sure garageband is connected to MIDI as well as having HairlessMIDI at serial 9600 and my arduino at serial.begin at 9600. everything seems to look good so far. I just don't know why I don't hear anything. Am I supposed to hear it from garageband, if so how?
here's my arduino code,
byte noteON = 144;//note on command
void setup() {
Serial.begin(9600);
}
void loop() {
MIDImessage(noteON, 60, 100);//turn note on
delay(300);//hold note for 300ms
MIDImessage(noteON, 60, 0);//turn note off (note on with velocity 0)
delay(200);//wait 200ms until triggering next note
}
//send MIDI message
void MIDImessage(byte command, byte data1, byte data2) {
Serial.write(command);
Serial.write(data1);
Serial.write(data2);
}

If I understood your setup correctly, you use:
an arduino with a sensor to generate a signal, this is the instrument
MIDISPORT USB http://www.performanceaudio.com/media/pdf/121/3757_m.pdf to make the link between the instrument and the computer
HairlessMIDI which converts a serial text protocol to midi. http://projectgus.github.io/hairless-midiserial/#getting_started
I am unsure you need the MIDISPORT at all. HairlessMIDI already makes the link between an Arduino program and a MIDI expander application (see tutorial in the link above).
According to this page, the Arduino must use the MIDI Library, and the init code looks like this.
void setup() {
MIDI.begin();
Serial.begin(115200);
}
Note the 115200 baud rate. The serial port on Arduinos must use a specific baudrate, otherwise the host and slave won't be able to talk to each other.
I think you must connect your setup to the MIDI In side on the HairlessMIDI application. If GarageBand is running, you must be able to select it in the drop down list.

Related

SoftwareSerial example not working as expected

I recently bought an Arduino UNO to read the data outputted by my Smart Meter. The meter uses serial communication and I would like to see the values being outputted on my laptop screen. I figured I would need to use the SoftwareSerial library to read the incoming data and print that data on my screen using the hardware serial and the Serial Monitor in the Arduino IDE. To become familiar with (software) serial communication on the Arduino, I reviewed the documentation of the SoftwareSerial library. Problem is, I can't get the most basic example to work and I have been stuck on this for quite a while now. The example code is below, the example can be found here
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
mySerial.println("Hello, world?");
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}
As far as I understand this, the following should happen:
- Type text in Serial Monitor window.
- Serial.read() reads this data and writes it to the Software Serial.
- The Software Serial reads this data and writes it back to Serial.
- That which was written appears on the screen.
But whatever I try, nothing happens. Among things I tried to following:
- Change the baud rate for both software and hardware serial (9600 for instance).
- Tried a different SoftwareSerial library (AltSoftSerial).
- Tried different RX and TX pins for SoftwareSerial.
- Instead of Serial.write(mySerial.read());, store the result in a char first.
I'm probably missing something obvious. I would be grateful to anyone who could shed some light on this or offer an alternative way for me to read the data from my Smart Meter.
Edit
I had no wiring, because the example specified "There is no circuit for this example". I tried all three options suggested by #slash-dev, but none had the expected behaviour:
SoftwareSerial with wires connecting pin 1 to pin 10 and pin 0 to pin 11. It prints strange characters:
Goodnight moon!
Ùniÿhtÿmoÿn!ÿ
nihtmoÿttt
AltSoftSerial with wires connecting 1-8 and 0-9. First prints Goodnight moon! and then it keeps printing Ô당¥�¡Ñ�moon!.
NeoSWSerial with wires connecting 1-10 and 0-11. Same as AltSoftSerial but keeps printing Ôë‹–+ë¡Ñ�j½½¹…j.
The baud rates must be the same on Serial and mySerial.
And you don't describe the connections, so I have to ask: Did you connect a wire from pin 1 (Serial transmit) to pin 10 (mySerial receive), and another wire from pin 0 (Serial receive) to pin 11 (mySerial transmit)? Note how they are crossed.
AltSoftSerial is really the best choice, but it only works on pin 8 (RX) and pin 9 (TX), which would require connecting 8 to 1 and 9 to 0. SoftwareSerial is very inefficient, because it disables interrupts for long periods of time. This can interfere with other parts of your sketch or other libraries.
My NeoSWSerial library is another alternative. It's almost as efficient as AltSoftSerial, but it works on any two pins. It can transmit and receive at the same time (unlike SoftwareSerial), but it only works at bauds 9600, 19200 and 38400.
EDIT:
I think what you've tried is probably working ok. All the software serial libraries use interrupts for processing individual bits instead of one interrupt per character. When there are other interrupts in the system (millis() TIMER0 or Serial), the bit "calculations" can be affected. This manifests as receiving the wrong byte. Your loopback test makes it especially susceptible because the sending and receiving are synchronized (the initial receive interrupt occurs while the transmit interrupt is starting the next char).
If you just hook 0 to 1, I think it will work, because the UART is able to send and receive at the same time, and it deals with complete characters, not bits. The character interrupts do not disturb the sending or receiving of the bits.
In developing the NeoSWSerial library, I have seen this manifest the same way. I had to use two Arduinos to fully test asynchronously (i.e., not synchronized). In your case, using AltSoftSerial for the SmartMeter should work fine, and you can choose different baud rates. If you are echoing the SmartMeter characters to Serial, be sure you have a higher baud rate on Serial.
This is most likely not related to the issues now 5 years ago, but in my case I was using the Arduino IDE 2.0.0-rc5 which was not writing to the soft serial for unknown reasons. I downgraded to Arduino IDE 1.8.19 and the same serial sketch worked.

Interfacing a USB/serial device with Arduino USB/serial interface

On one side I have a device with a USB (FTDI chip) interface communicating in serial 9600bps,N,8,1 - the default configuration for the Arduino USB/serial interface.
On the other side I have a simple Arduino sketch that starts a serial session and transmits data.
void setup() {
// put your setup code here, to run once:
Serial.begin(9600,SERIAL_8N1);
}
void loop() {
// put your main code here, to run repeatedly:
char* data_to_send="66";
SSEND(data_to_send);
delay(5000);
}
String SSEND(char* data){
String protocol="AT$SF=";
protocol+=(String)data;
// protocol+="\r";
Serial.println(String(protocol));
delay(1000);
return "OK";
}
The sketch works just fine when connected to the computer.
Then I try to connect to the device and I see the Tx LED that stops blinking so it doesn't send anything and of course the device doesn't work like expected. Besides, I tried sending serial commands directly from the computer to the device and it works just fine.
So my questions are:
Why does the serial interface between Arduino and my device doesn't work?
Why does Arduino stop sending data once the USB/serial interface switched from the computer to the device
What would be the solution to make the device work with the Arduino?
Should I switch the TX & RX with a splitted FTDI cable plugged to port 0 and 1?
Thanks for your help
I suspect that device is a USB device and not a USB host, and you plugged two USB devices together. That Arduino is not a USB host, and a USB connection always needs a host.
The plug adapter you're using is not even supposed to exist according to the USB spec, because the different shapes of plugs are specifically there to make it impossible to plug two devices into each other like you've done here.
The way to make it work would be to use another board that actually supports acting as a USB host.

Reading serial data from Arduino fails

I have written a program for Arduino that reads some analog signals and sends them to the computer when it receives a command from the master computer. I wondered why this didn't work on the computer it was intended to run on. On my own computer it runs fine.
I uploaded a simple test code in the Arduino.
void setup() {
Serial.begin(9600);
}
void loop() {
if(Serial.available()) {
Serial.println(Serial.read());
}
}
This doesn't run on the second computer either. When I use Arduino serial monitor for transfering data, I see the RX led blink but not the TX. With the computer it's working on, I can see both of the leds flash. Arduino receives the data on both computers, but the second computer doesn't receive Arduino's responses. What might be wrong?
Edit. I forgot the Arduino hooked up to the problematic PC for a few minutes and tried it again. Then it worked! It seems like it needed some time to warm up. Why's that?
Sometimes it can take a second for the Arduino and computer to establish the Serial handshake, especially at 9600 baud. I'm glad you got it working!

Bluetooth RN41 does not respond

I want to send some commands to my RN41 Bluetooth Module connecting to Arduino Leonardo over the serial port using serial monitor, as the tutorial shows. But it does not respond. I can connect to the bluetooth modul and the status LED blinks right. I tried to send $$$ to change to command mode, and the blink rate does change to 10/sec, but module responds nothing. And when I send '---', the blink rate back to normal. I think it means the connection is successful but I just cannot see anything at serial monitor.
I set monitor's baud to 9600, as exactly the tutorial shows. (https://learn.sparkfun.com/tutorials/using-the-bluesmirf/example-code-using-command-mode)
Do you guys know what could be wrong?
Code attached:
/*
Example Bluetooth Serial Passthrough Sketch
by: Jim Lindblom
SparkFun Electronics
date: February 26, 2013
license: Public domain
This example sketch converts an RN-42 bluetooth module to
communicate at 9600 bps (from 115200), and passes any serial
data between Serial Monitor and bluetooth module.
*/
#include <SoftwareSerial.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
}
void loop()
{
if(bluetooth.available()) // If the bluetooth sent any characters
{
// Send any characters the bluetooth prints to the serial monitor
Serial.print((char)bluetooth.read());
}
if(Serial.available()) // If stuff was typed in the serial monitor
{
// Send any characters the Serial monitor prints to the bluetooth
bluetooth.print((char)Serial.read());
}
// and loop forever and ever!
}
I was stuck on very simple case:
To enter command mode you have to send $$$ without any CR/LF.
after you entered command mode you have to send commands, and every command has to be followed by CR LF. if not - module will not response.
Hope that helps.
Yes, send only 3 characters, "$$$". I was also stuck for a bit. I also found that reading the Mate response "CMD" is necessary, which is not shown in the published sketch.
I've got some brandnew RN41VX modules.
I connect them by a XBEE Explorer USB module (almost same as RN41 EVAL Kit) to computer.
Using a terminal with 115 kbaud I send $$$ (without any trailing chars as 0x0d) to get into command mode. The LED switches to 10Hz blinhking - all fine.
But no respone appears in terminal.
Solution:
I had to switch on RTS Signal, even if manual tells "Flow Control: none"
kind regards Volker

Arduino: Incoming USB serial data when USB is disabled hoses the connection

I'm writing a sketch for an Arduino Leonardo that occasionally needs to communicate bidirectionally via USB serial, and also needs to be power efficient. To save power I'd like to disable the USB when it's not needed. I can successfully use power_usb_disable() and power_usb_enable() to do this, BUT only if no data is sent to the Arduino when USB is disabled.
Here's how to reproduce the problem: I run the following sketch on the Leonardo while it's connected to a serial comms program on my computer (I've tried the Arduino serial monitor and Minicom in Linux and PuTTY in Windows). It works as expected, printing out the messages, until I type something right after the "Disabling USB..." message. Once I do that, I will receive no further data from the Leo. The funny thing is, the TX and RX LEDs continue to blink as if everything is fine. The only way to get the connection working again is to reset the board.
Now, I don't really care about dropping the incoming data when USB is disabled, that's to be expected...but I would like the serial connection to continue to work correctly once USB is enabled again.
I don't know enough about how USB serial works to know how to troubleshoot this.
#include <avr/power.h>
void setup() {
Serial.begin(9600);
delay(3000);
}
void loop() {
Serial.println("USB is enabled!");
delay(1000);
// If I send characters here, everything is fine.
Serial.println("Disabling USB...");
delay(25);
power_usb_disable();
delay(1000);
// If I send characters here, it hoses the USB connection somehow.
power_usb_enable();
delay(25);
}
I guess for now the best answer to this problem is "don't do that." I can arrange not to disable the USB if the connection is open, using the "if (Serial)" thing. So if somebody has a serial monitor open and looks as if they're about to type something, I leave USB enabled. Seems to work OK, although it doesn't address the underlying general question of how to robustly disable and re-enable USB from any state it might be in. I would still love to hear expert advice on that.

Resources