Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Audio board and hc05 module don't work toghether

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Posts
    18

    Audio board and hc05 module don't work toghether

    Hi everyone, I'm working on a project with teensy 3.6, audio board and the module hc-05. I use the virtuino app to communicate with the module https://play.google.com/store/apps/d...virtuino&hl=it. I wanted to verify if they could work toghether, therefore I wrote two scripts.
    The first is a simple Passthrough for the audio shield
    Code:
     
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           //xy=227,171
    AudioOutputI2S           i2s2;           //xy=570,177
    AudioConnection          patchCord1(i2s1, 0, i2s2, 0);
    AudioConnection          patchCord2(i2s1, 1, i2s2, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=558,268
    // GUItool: end automatically generated code
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
      sgtl5000_1.unmuteHeadphone();
      sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
      AudioMemory(60);
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    }
    I compile it and it works well.

    the second script aims to verify whether the virtuino app talks to the teensy, so I wrote this second code
    Code:
     
    #include "VirtuinoBluetooth.h"
    #include <SoftwareSerial.h>  
    SoftwareSerial bluetoothSerial =  SoftwareSerial(9,10);    
    VirtuinoBluetooth virtuino(bluetoothSerial);        
    
    int value;
    
    void setup() {
      // put your setup code here, to run once:
      virtuino.DEBUG=true;
      Serial.begin(9600);
      bluetoothSerial.begin(9600);
    }
    
    void loop() {
      virtuino.run();
      value=virtuino.vMemoryRead(30);
      Serial.println(value);
    }
    I connect the VGG to the Vin (since hc-05 require 3.6-6V, using the usb port to power teensy), in the app I added a virtual switch and it works well. I also tried to use differents rx&tx pin, 31 and 32, but it doesn't work, if someone know the reason why I'd like to know, but it's not so important.
    Finally I merged all together to try if I could control an audio project using the virtuino app. So I wrote this code:
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include "VirtuinoBluetooth.h"
    #include <SoftwareSerial.h>
      
    SoftwareSerial bluetoothSerial =  SoftwareSerial(9,10);   
    VirtuinoBluetooth virtuino(bluetoothSerial);   
    
    int value;
    
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           //xy=227,171
    AudioOutputI2S           i2s2;           //xy=570,177
    AudioConnection          patchCord1(i2s1, 0, i2s2, 0);
    AudioConnection          patchCord2(i2s1, 1, i2s2, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=558,268
    // GUItool: end automatically generated code
    
    void setup() {
    
      virtuino.DEBUG=true;
      Serial.begin(9600);
      bluetoothSerial.begin(9600);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
      sgtl5000_1.unmuteHeadphone();
      sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
      AudioMemory(60);
    
    }
    
    void loop() {
    
      virtuino.run();
      value=virtuino.vMemoryRead(30);
      Serial.println(value);
    
    }
    It's simply the previous two scripts in one. Then I filled it and the first thing I noticed is that the led on the teensy board was off. I tried to use it and the virtuino part of the code was working but the audio wasn't.
    There is something I am mistaking, but I don't understand what is it. If anyone has any idea and is available to share it, I would appreciate that. If you need more info about the problem please ask me. Thanks you all for your help.

    Moreover, I would like to know also if it's possible to power teensy using a power bank with 5V. Thanks again.

  2. #2
    Member propa's Avatar
    Join Date
    Apr 2018
    Location
    UK
    Posts
    93
    I see one problem.

    The audio shield uses pins: 9, 11, 13, 18, 19, 22, 23

    In your code you have defined SoftwareSerial as (9,10), I'm assuming those are the pins you are using. Take out the reference to pin 9 that the audio shield uses.

    If you're using the SD card on the shield also take out any reference to these pins: 7, 10, 12, 14.

    18,19 are shareable (i2c), and 7, 12, 14 are sharable with other SPI chips.

    Lastly yes is perfectly fine to power off a power bank with 5v, the usb port on your laptop/pc sends out 5v, and the teensy functions perfectly fine.

    Let me know if that solves the problem.

  3. #3
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,380
    ... and why would on use this atrociously resource consuming software serial (which does bit banging via GPIO) on a Teensy 3.6 which has 6 native hardware serial ports?

    Software serial risks to never work together with the audio library because the latter uses rather lengthy interrupt routines to process audio data blockwise. And a serial communication which is interrupted every 2.3ms will just not work.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,913
    Quote Originally Posted by Carlo alfisi View Post
    I also tried to use differents rx&tx pin, 31 and 32, but it doesn't work, if someone know the reason why I'd like to know
    Pins 31 & 32 are a good choice. We could help you more if you actually show us what you really tried, like posting that code and showing photos of the wiring. A link to the VirtuinoBluetooth.h library you're using would also help, so we don't have to guess about this library.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,913
    Quote Originally Posted by Theremingenieur View Post
    atrociously resource consuming software serial
    However, on Teensy 3.x, the SoftwareSerial library is merely a thin wrapper for real hardware serial. So it requires using a pair of pins with serial capability, and gives you real serial that doesn't block audio like traditional software serial would.

    I don't know anything about this other library, but from the code shown here, it looks like it's designed to take a SoftwareSerial reference. We have the thin SoftwareSerial wrapper for exactly this sort of situation, where libs designed for Arduino Uno (with no free serial ports) are hard-coded to expect SoftwareSerial. It lets you use real serial ports with those sorts of libraries that normally would only allow software serial.

    SoftwareSerial on Teensy 3.x also has transmit-only bitbanging code if the chosen pins aren't a real hardware serial port. Theremingenieur is right, that should be avoided if using audio (or pretty much anything needing interrupts).

  6. #6
    Junior Member
    Join Date
    Dec 2018
    Posts
    18
    thanks propa for the advice about the pin 9&10. PaulStoffregen this is the link for the virtuino library https://virtuino.com/downloads/virtuino.zip. with this setup the comunication with virtuino works well Click image for larger version. 

Name:	setup1.jpg 
Views:	3 
Size:	74.5 KB 
ID:	16594. here the pin used are the 9&10

    if I use the 31&32: Click image for larger version. 

Name:	setup2.jpg 
Views:	3 
Size:	69.9 KB 
ID:	16595 the comunication doesn't work. Maybe it's due to a wrong soldering of the pin or to the bad breadboard, tonight I'll try to make same try to verify this possibility. I'll say if it works or not

    about what Theremingenieur said, sorry I don't know the difference between Software and Hardware Serial, the virtuino library allows to use the HardwareSerial but the code in its example doesn't compile, it's the following
    Code:
    #include "VirtuinoBluetooth.h"               // Include VirtuinoBluetooth library to your code
     VirtuinoBluetooth virtuino(Serial1);        
                                                     
    void setup(){
      
      virtuino.DEBUG=true;               // set this value TRUE to enable the serial monitor status
      Serial.begin(9600);                // Set serial monitor baud rate
    
      Serial1.begin(9600);             // Set the hardware serial baud rate
      
      }
    
    void loop(){
       virtuino.run();           //  necessary command to communicate with Virtuino android app
       }
    I wrote to the virtuino's mail, but he doesn't respond. if anyone found the error in this code, and if this comunication method is best, for my code is fine.

    Finally, If Ichange the RX&TX to 31&32 , do the audio board should work together the HC-05?
    One more question, the best sd-card port to play and record is the Audio shield's one or the Builtin's one?

  7. #7
    Junior Member
    Join Date
    Dec 2018
    Posts
    18
    I change the rx&tx pin to 31&32 but it still doesn't work.... so I decide to use the pin 0&1 for rx&tx and this code works
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include "VirtuinoBluetooth.h"
    #include <SoftwareSerial.h>
      
    SoftwareSerial bluetoothSerial =  SoftwareSerial(0,1);   
    VirtuinoBluetooth virtuino(bluetoothSerial);   
    
    int value;
    
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           //xy=227,171
    AudioOutputI2S           i2s2;           //xy=570,177
    AudioConnection          patchCord1(i2s1, 0, i2s2, 0);
    AudioConnection          patchCord2(i2s1, 1, i2s2, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=558,268
    // GUItool: end automatically generated code
    
    void setup() {
    
      virtuino.DEBUG=true;
      Serial.begin(9600);
      bluetoothSerial.begin(9600);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
      sgtl5000_1.unmuteHeadphone();
      sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
      AudioMemory(60);
    
    }
    
    void loop() {
    
      virtuino.run();
      value=virtuino.vMemoryRead(30);
      Serial.println(value);
    In the output there's a little noise due to the Bluetooth connection, I would know if there's a way to screen it.
    thanks a lot to all of you for the help, I will show my total script for the loopstation when I'll finish it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •