Skip to content
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

No connection to Carduino #8

Open
Paul-C-S opened this issue Jul 4, 2020 · 16 comments
Open

No connection to Carduino #8

Paul-C-S opened this issue Jul 4, 2020 · 16 comments

Comments

@Paul-C-S
Copy link

Paul-C-S commented Jul 4, 2020

Hi,

First of all, great project! I've sent you some beer money :)

I am struggling with a problem and hope you can help. I cannot get Cardroid to connect to the Nano. I'm pretty sure that's what the problem is because if I use a serial monitor on my Android device I can see the message "Entering Configuration Mode Success!" and "Setting Baudrate Successful!" so I think this means the Nano is communicating with the MCP2515 board OK (see attached):

Terminal in HEX mode

Cardroid shows this:

Car monitor not connected

I am not 100% sure the MCP2515 is communicating with the car or not at this stage.

For reference, here is now I wired up the Nano, etc.

Carduino Connections

If you can offer any advice or diagnostic tips I would really appreciate it!

Paul :)

@rampage128
Copy link
Owner

rampage128 commented Jul 5, 2020

Hey Paul! Great to see your progress!

From what I can tell from the serial output, the protocol does not look like it is the correct version. Make sure you are running https://github.com/rampage128/carduino on your atmega. The niscan project is currently not supported due to a rewrite of the core that is now taking longer than expected.

Also the app has a devices area. Any device the app ever manages to communicate with should be listed in that area (also after the device disconnects again). That will be a sure sign, that you have a connection.

Let me know how it turns out when you use the other firmware!

@Paul-C-S
Copy link
Author

Paul-C-S commented Jul 5, 2020

Thank you for your reply :)

Ah, that makes sense. I was not running that version!

I have just tried to compile that and I am getting this error:

carduino:16:28: error: 'onCarduinoSerialEvent' was not declared in this scope

Carduino carduino(&Serial, onCarduinoSerialEvent, onCarduinoSerialTimeout);

                        ^~~~~~~~~~~~~~~~~~~~~

carduino:16:51: error: 'onCarduinoSerialTimeout' was not declared in this scope

Carduino carduino(&Serial, onCarduinoSerialEvent, onCarduinoSerialTimeout);

                                               ^~~~~~~~~~~~~~~~~~~~~~~

I must be doing something wrong!

@rampage128
Copy link
Owner

It could be that the order of code needs to be different than it is. I use an IDE that automatically generates some stuff when compiling so I do not see that error.

You can however look for a function with that name 'onCarduinoSerialTimeout' and redeclare that function above the line causing the error.

I will address that issue asap and change the code myself. Unfortunately I am currently still in hospital recovering from surgery (everything is fine). As soon as I am out, I will address this issue.

@BlackSummers
Copy link

BlackSummers commented Jul 5, 2020 via email

@Paul-C-S
Copy link
Author

Paul-C-S commented Jul 5, 2020

Thank you both for your quick replies!

I have been able to compile the code now but I am still having issues unfortunately. I edit the code to use the same right pins for my MCP and that bit works OK. But I still cannot see the device on CarDroid.

I see there is something around the powerManager but I have not connected anything to this. Might this be the problem? Is there anything else I need to do (I see it reads the door open, etc. but I guess that doesn't matter to me)?

I have not connected the steering controls but I guess that isn't causing any problems.

I hope you have a speedy recovery Fred.

@rampage128
Copy link
Owner

I see. The code is for a prototype, that uses hardware to

  • Control charging of an android tablet (PowerManager)
  • Turn on and off other peripherals on the hardware (serial chip and so on) (PowerManager)
  • Send the chip to sleep, when some conditions are met and wake it back up using an interrupt line (PowerManager)
  • Steering Wheel remote (NissanSteeringControl)
  • Can reading (Can)

The PowerManager is a way to make it easier to control power related functions without having to touch the low level code required for that. It provides you with callbacks to determine when the hardware should go to sleep and what to do when it wakes up. To do that it wraps around the carduino implementation. You can see that we call powerManager.update(...) in the loop() function. That one just checks onSleep to see if the chip should go to sleep. If not it will call onLoop() to execute whatever we want to do when the chip is not sleeping. Also it will call onWakeUp() if it was woken up from sleep by a hardware interrupt.

Long story short. If you want to disable the handling of the sleep mode (let's say you have your hardware hooked up to ACC anyways and don't need it to sleep), you can just make the following changes in the carduino.ino file

  • remove the PowerManager include and declaration
  • replace the contents of loop() with the contents of onLoop().
  • remove onSleep() and onWakeUp()
  • remove all other usages of powerManager
  • remove Some of the sleep specific code lines, that now are not used anymore (if you want)

That should do the trick

@Paul-C-S
Copy link
Author

Paul-C-S commented Jul 6, 2020

Thank you for your detailed reply! I have tried that but I am still having problems. There are still no devices being shown in CarDroid. Do the devices only show when successful contact has been made to the 370Z CAN, or does something show once CarDroid makes contact with the Nano?

I don't know if this helps, but this is the serial output:

Serial dump

Sorry to be a pain!

@rampage128
Copy link
Owner

rampage128 commented Jul 6, 2020

The serial output looks good. What you see there {a........} are the connection requests from the hardware.

So there is one thing about how device detection and serial communication works. Device detection in android happens when a device is physically connected. All apps that subscribe to it will get a notification that a device with a specific hardware has connected. There is a way to manually enumerate and connect to devices, but the app currently does not support that (there is some problems with that which I didn't have time to solve yet). Also Serial devices can only be used by one app at a time (in android any device can only be used by one app at a time AFAIK).

So when the hardware is connected to the android device for the first time, the system should ask you if you want to allow cardroid to use this device. It is recommended to allow this and also check the box "set as default". If the popup does not appear, then you probably have set another app as default for that device. In that case you have to clear this option from the app where it was set (you can do that in the android system settings of the corresponding app).

If you reconnect the device, make sure that you have no other app running, that will auto connect to the device quickly because a serial device can only be used by one app at a time. That is a limitation of serial communication. Also your serial monitor will hog the connection and not allow the app to connect.

edit: Inside the app it works like that... The app receives the notification of the new device, you get the screen asking you for permission, you say yes, the app will execute code to try to make a serial connection. On success it will receive the connection requests from the hardware and then identify the hardware. At that point, you should see a device entry in the devices section of the app. Normally that happens within 2-3 seconds of a device connecting.

@Paul-C-S
Copy link
Author

Paul-C-S commented Jul 8, 2020

This is very helpful! I remember that about serial apps before but it was a good reminder.

So, this is where I am now. I have 3 different Android devices and they all behave in the same way. I have uninstalled all serial apps including CarDroid and restarted the device. I then installed CarDroid and gone into the app to set the permissions for the overlay.

The first time I plug in the Nano, Android asks me if I want to use CarDroid and if I want it to be the default App - so I set this on.
However, CarDroid doesn't launch. When I remove and reconnect the Nano it still doesn't launch. So I think this must be the issue.

Some other Apps I use will launch when I plug in a device, such as an inspection camera.

I have tried this with 3 different Android devices and it is the same. The devices run Android 8.1 and 10 and I have compiled the APK for each of them.

I am using Android Studio 4.0 to compile the APKs. Could I be doing something wrong compiling them? CarDroid runs if I manually launch it, but it does not connect.

Finally, does Android need to be rooted for this to work? None of my devices are.

Thank you, as ever, for your help with this!

@rampage128
Copy link
Owner

The app does not need root. Also the version of Android studio should not matter much, as long as it is able to compile the app.

if no device is detected, then the app can not communicate with the device or does not successfully identify the device.

  • Make sure that your atmega uses one of the supported default baud rates (preferably 115200) (you can check in the sketch which baudrate it uses).
  • You can try to increase the detection timeout under Settings > Advanced > Compatibility Settings > Timeout (value is in ms)

That the app does not open anything visibly is intended behaviour.

When you connect a device, the app will open a background service, that tries to identify and connect to the device if possible. If a device is successfully identified, the background service will create a database entry for that device (that entry will show up inside the devices section of the app). Other than that the background service does nothing except listening for data from that device and keeping the connection open.

As soon as the background service could identify that it is a supported device (of any type), it will create a database entry. Such an entry will show up under "Devices" in the dashboard. If the Devices view is just a blank page, then the app never detected a device (The devices will also stay listed there even when they disconnect).

For the overlay to appear you have to select the device that should trigger it in the settings of the App yourself.

In the settings the first 3 options under the headline Default Devices allow you to select a device for

  • Car Connection: a device that will provide the CAN/SWR data from the car)
  • Location Emulation: a device that provides GPS data to allow android devices without internal GPS to use navigation
  • Overlay: a device that will trigger the overlay to appear on screen

If you tap one of these settings and it only shows the option None in the popup, then no device has been detected ever.

@Paul-C-S
Copy link
Author

Thank you again for such a useful and detailed reply.

It does seem like the app doesn't recognise the device. I do not have any devices listed under Default Devices at all. I would say something on my Android device is stopping it from working but I have not been able to make it work on 3 devices. Unless there is something I am missing when I compile it. It compiles the APK with no warnings or errors.

On paper my Nano should support 115200 baud and that it was it was communicating at when I screenshot the comms received by the serial monitor app. I have tried lowering the baud and increasing the timeout but it hasn't fixed the issue unfortunately.

I will keep trying different things (I might try and rewrite the code to work with a Teensy 3.2 I have spare). I will not give up!

Thanks again for your help. I will let you know if I make any progress. If you can think of anything else to try in the meantime please let me know!

@Paul-C-S
Copy link
Author

I have another question! Should the Android App be able to detect and communicate with the Nano even if the Nano is not connected to the 370Z CANBUS?

If the Nano needs to be connected to the 370Z before the app recognises it then maybe the problem is there and not between Android and the Nano.

@rampage128
Copy link
Owner

The app should recognize the nano independent of it's internal features.

@Paul-C-S
Copy link
Author

In that case none of my Android devices have ever recognised the device for some reason.

I bought a new Nano, exactly the same model as the one in your link and it's no different. As we've proved, the Nano is sending out the right serial traffic to Android so I can only think I must be doing something wrong compiling the APK. But I can't think what! Would you be able to upload your APK somewhere so I can try a known working one?

Thanks again!

@rampage128
Copy link
Owner

There is no way, that compilation causes these kind of issues.

I would recommend you to set up WIFI debugging so you can use logcat and breakpoints to check what is happening. logcat will already give you information on individual steps of device detection without changing any code. And it is easy to extend the log output by adding individual lines of code for logging.

My current guess is: It can only be a communication issue or invalid data in the serial output somewhere. I could also imagine it being a serial driver issue with the specific devices you use ... but that is rather unlikely.

Whatever it is, setting up a proper debugging is the only way you can find out. I can not reproduce the issue with any of my 10 android devices and have not heard of it in 6 other projects where people use the app/firmware in different configurations. So I can not really give you any further advice without further detailed facts on what causes the issue.


I would also recommend you to get a proper serial monitor (like hterm) for your PC and test that the hardware sends the correct packets without any issues. I know I said the output from your android terminal looks good, but there could still be issues that are not visible in that terminal app since it is outputting plain text sometimes.

@Paul-C-S
Copy link
Author

Paul-C-S commented Aug 4, 2020

Hi and thanks again for your reply. As you can guess from the delay, I haven't had a lot of time to put into this project recently. I have tried some debugging but didn't get very far. So I've changed direction...

Instead, I am using your Niscan project as a basis to interface with physical controls and status screen. It's early days but I am getting results :) I have a stability issue where the Arduino locks up and stops working at random times but I am looking into that!

I can't say what is causing my issue interfacing with the Android app but I think maybe I should close this issue down since others have not had a problem and I don't want to waste any more of your time.

I hope you are better now. Paul :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants