-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Power on BT module only if HU in CD-changer mode #17
Comments
On the hardware side you could add a relay or a suitable NPN transistor to control the power of the module. Software-wise: The protocol allows for this for sure, but @visualapproach would need to add some code to handle that (I didn't look at the code, so no idea how possible that is). |
Hardware for me is no problem. The Arduino output controls the transistor that powers the BT module. The question is: it can be programmed? @visualapproach ? Does Arduino get a message from HU that the CD-changer is on? |
Sure thing, I Will have a look at it and post somerhing soon. |
I will be waiting for a good news. :-) |
Code removed and reposted for readability |
check lines 43 and 713-740 |
I have connected according to: older_stuff/schematics_melbus_hack_v2. |
No, you shouldn't have to change PLAY PIN. What you wanna do is to capture POWERON-message and switch on the transistor. If POWEROFF is received, you turn off the transistor. That's all you need to change. If you use the old code (v7i line 255 onwards), look at the following snippets and adjust according to my suggestion:
If you are using the newest code, do the same, but at lines 713 onwards:
Ofc remove the arrows. They are just for your attention. |
And in the "void setup ()" section I have to add: |
Yes. Wish you luck, and let us know if it works. |
@visualapproach Maybe you can patch this in the repo; I think the feature doesn't do any harm if it goes unused. |
Wait. First, I'll do the tests. Then I will draw a connection diagram. OK? :-) |
Yeah sure. If it works for BK-Poland I'll update the repo |
And thanks all for keeping this project alive! |
The first test (older stuff code) was quite good. There is only one problem. Output D5 is in a high state also when I listen to the internal CD (HU). |
Ok I’ll have a look at it. |
|
@BK-Poland I couldn't find anything obvious. What happens when you go from CDC->FM->CD ? Does the D5 go high->low->high? |
Yes, exactly. |
There is one more interesting thing. When I switch CDC-> CD, the BT module will restart. So Arduino turns off D5 at 100ms or maybe max 200ms. You can see how the LED in the BT module goes out for a moment. |
Can you hook up a computr via USB and log serial output? |
(Don’t forget to uncomment the transmission logging in Main loop) |
Sure. But... How can I do this? :-) |
Arduino in car, hooked up to computer via USB. Use arduino IDE to Reprogram arduino with new software (uncomment the logging part by removing the double slashes). Then turn on radio and watch the serial monitor in IDE. Switch between sources and then copy text |
OK. I need 30 minutes. I'll be back... :-D |
I do not know what I'm doing wrong, but the serial monitor does not work. Communication is correct, but nothing is there. Empty serial monitor window. |
Need to sleep now. I get back to you. Check correct port and baudrate 115Kbps (i think) |
They are correct. I need to learn Arduino IDE :-) |
I have a stupid question: Do I have to remove all double slashes from all lines with "Serial.println" and "Serial.print"? |
yeah it's code related. I'll investigate. Could you send me your code by email? |
/* By Thomas Landahl, 2017-04-25 */ #define MELBUS_CLOCKBIT (byte)2 //Pin D2 - CLK //volatile variables used inside and outside of ISP byte byteToSend = 0; //global to avoid unnecessary overhead //preset parameters //Base adresses. //change theese definitions if you wanna emulate another device. //This list can't be too long. We only have so much time between the received bytes. (approx 500 us) //arrays to send to HU when requested //TRACK INFO
*/ //CARTRIDGE INFO //MASTER MODE INFO void setup() { //All lines are idle HIGH //LED indicates connected status. //Activate interrupt on clock pin //Initiate serial communication to debug via serial-usb (arduino) //Call function that tells HU that we want to register a new device //Main loop Connected++; //Do other stuff here if you want. MELBUS lines are free now. BUSY = IDLE (HIGH) //Reset stuff //Incoming serial data is supposed to look like this: // I haven't seen any advantages from sending messages to HU. flag = false; //don't print during next loop. Wait for new message to arrive first. //Notify HU that we want to trigger the first initiate procedure to add a new device (CD-CHGR) by pulling BUSY line low for 1s // Wait until Busy-line goes high (not busy) before we pull BUSY low to request init pinMode(MELBUS_BUSY, OUTPUT); digitalWrite(MELBUS_BUSY, HIGH); //This is a function that sends a byte to the HU - (not using interrupts) //Convert datapin to output //For each bit in the byte //Reset datapin to high and return it to an input //Enable interrupt on INT0, quicker than: attachInterrupt(MELBUS_CLOCKBIT_INT, MELBUS_CLOCK_INTERRUPT, RISING); //Global external interrupt that triggers when clock pin goes high after it has been low for a short time => time to read datapin //if all the bits in the byte are read:
} void SendTrackInfo() { void SendCartridgeInfo() { void reqMaster() { void masterSend() { void fixTrack() { //Simulate button presses on the BT module. 200 ms works good. Less is not more in this case... void prevTrack() { void play() { void volumeDown() { } void volumeUp() { } //Happy listening, hacker! |
change line 182 to if ((matching[cmd] == cmdLen[cmd]) && (byteCounter+1 == commands[cmd][0])) { and try again. |
Something is wrong. Now HU does not detect the CDC. So... |
if ((matching[cmd] == cmdLen[cmd]) && (byteCounter+1 ==cmdLen[cmd] )) { |
It works! Perfectly! A big beer for you. Thank you! |
OK. Time to sharezone my hardware. I use the MOSFET IRL540N (logic level). I use gate resistor 1Mohm. Its simple to make a new function :-) |
Awesome! Cheers |
Do you need me to draw my wiring diagram? If I can help, please write. You can publish my idea in the official code. |
Please do! I’ll update the code also. May I ask why you are using the old code? Legacy or doesn’t the newer code work in your application? Just curious. |
Why do I use the old code? It's simpler and it's enough for me. It's easier for me to analyze it. It meets all my requirements. BT works in my old Volvo. Thank you very much for that! When I was doing my BT-Volvo-Car according to your instructions and with your code it was still an old code. Maybe I will try a new code in the future. In what program do you draw your electrical diagrams? |
Ok, I understand. If you are happy then no need to switch code :-) |
I remember that I had to draw a diagram. I'm working on one more improvement. I am waiting for a shipment (with some electronics parts) from China. A month or two. Please be patient. :-) |
No worries. I will update the code also. Some day :-) |
I have a problem with the hardware layer. Sometimes the BT module turns itself on. Sometimes Arduino goes crazy and I have CD Error on the HU display. Even, he sometimes switches the songs himself. It seems to me that disconnecting GND of the BT module is not a good solution. If I do a properly working layout, I will show the diagram. Please be patient. :-D |
I found the fault. The Arduino Nano stabilizer on the PCB was damaged. The damage was revealed only after a few minutes of work. But sometimes only after an hour. I used a step-down converter and Arduino has 5V power supply. I have one more request for help: Is it possible to do so that Arduino does not turn off BT when shooting the starter? |
I will write in words how this code could work in "case 7": |
It would be possible with a local powersupply that lasts for the duration of you shooting the starter. Like a battery or capacitor. |
Yes I know. I've already done direct battery power. Arduino and BT have power supply always. |
Try this: //Main loop
... if (mytimer_enabled) { //add this function: |
any success? |
I am sorry that I have not written for so long. I had a lot of work and not enough free time. Unfortunately it does not work. Normally turns BT on and off without delay. |
/* By Thomas Landahl, 2017-04-25 */ #define MELBUS_CLOCKBIT (byte)2 //Pin D2 - CLK //volatile variables used inside and outside of ISP byte byteToSend = 0; //global to avoid unnecessary overhead //preset parameters //Base adresses. //change theese definitions if you wanna emulate another device. //This list can't be too long. We only have so much time between the received bytes. (approx 500 us) //arrays to send to HU when requested //TRACK INFO
*/ //CARTRIDGE INFO //MASTER MODE INFO void setup() { //All lines are idle HIGH //LED indicates connected status. //Activate interrupt on clock pin //Initiate serial communication to debug via serial-usb (arduino) //Call function that tells HU that we want to register a new device //Main loop Connected++; if (mytimer_enabled) { //Do other stuff here if you want. MELBUS lines are free now. BUSY = IDLE (HIGH) //Reset stuff //Incoming serial data is supposed to look like this: // I haven't seen any advantages from sending messages to HU. flag = false; //don't print during next loop. Wait for new message to arrive first. //Notify HU that we want to trigger the first initiate procedure to add a new device (CD-CHGR) by pulling BUSY line low for 1s // Wait until Busy-line goes high (not busy) before we pull BUSY low to request init pinMode(MELBUS_BUSY, OUTPUT); digitalWrite(MELBUS_BUSY, HIGH); //This is a function that sends a byte to the HU - (not using interrupts) //Convert datapin to output //For each bit in the byte //Reset datapin to high and return it to an input //Enable interrupt on INT0, quicker than: attachInterrupt(MELBUS_CLOCKBIT_INT, MELBUS_CLOCK_INTERRUPT, RISING); //Global external interrupt that triggers when clock pin goes high after it has been low for a short time => time to read datapin //if all the bits in the byte are read:
} void SendTrackInfo() { void SendCartridgeInfo() { void reqMaster() { void masterSend() { void fixTrack() { //Simulate button presses on the BT module. 200 ms works good. Less is not more in this case... void prevTrack() { void play() { void volumeDown() { } void volumeUp() { } void shutoffBT() { |
This line: static long unsigned int mytimer = 0;
I'm sure it is not 5 s. It's not a timer per se, it's a counter. It would be alot easier to time things if timers where on, but they might interfere with communication. As I commented in the code, you need to adjust the value yourself. If it takes 20 s to count to 500000 then you try 125000. |
It works! Exactly as I wanted. Thank you! :-) |
You’re welcome |
What kind of program did you use to draw the scheme of your project? |
Eagle |
hepinizi tebrik ederim |
Tack ska du ha |
Great job! Thank you! I have only one "little" dream: Is it possible to switch power on the BT module only when I switch to the CD changer in HU? BT turned off when I listen to FM radio.
The text was updated successfully, but these errors were encountered: