Hey everyone, long time reader first time poster here. Hopefully I have put this in the right section haha
Before I start I have to clarify that my project is in the planning stage. I know what I want the project to do and what hardware is needed (well I think anyway). My project is to replace the BCM (body control module) and the body loom of a car.
Essentially what I want to do is control lights from a central location ie drivers seat.
My plan is to have a raspberry pi as the central control unit then have several Arduino units, one in each corner to control the lights and power windows in it's quadrant.
So my issue is that I can't seem to find how to go about the software side of it. Although I have a few ideas I thought I should ask to see what would be do-able. All of them rely on the I2C bus to communicate between the RPi and Arduino's.
First Idea:
Individual functions for each case, ie brake lights on, brake lights on + indicator flashing, brake lights on + indicator flashing + reverse light. Each function would have an ID assigned to it that would correspond to the data being sent from the Pi.
The Arduino would wait til it gets a bit of data then loop til it gets a new bit of data.
Issue with this, lots and lots and lots of cases. Up to 115 just with the horn, brake lights, head lights (parkers, low and high) and reverse lights. Haven't finished the cases either yet.
Second Idea:
As above but functions within functions. ie have the basic light/horn on or off as their own functions but the more "complex" situations have these functions in them.
Third Idea:
Using each light as an object and calling more than one at once depending on the case.
I'm only new to working with hardware and software together. Have enough programming experience to understand what is going on though. Originally I wanted something to loop until I had sent another code to turn on or off another light at the same time which would involve running two or more loops simultaneously, however what I had read said this wasn't possible to multitask.
So my question are these.
Is what I'm proposing even possible?
Is what I have proposed over complicated? If so what's a simpler solution?
Are there any other methods of doing what I want to do? Aside from keeping the current system in the car.
I'm open to not using the I2C bus and using something else in place of it.
Any help would be useful
I haven't worked in that area, but I suspect you would be better off considering CANbus as the communication mechanism rather than stringing TTL serial cables around the vehicle. Also note that the electronic devices you're working with will be vulnerable to electromagnetic and electrical noise and there is a lot of both in a running car - you would need to pay attention to electrical and electromagnetic isolation and protection.
Thanks for your reply PeterH,
I am aware of electromagnetic interference and looking at ways to reduce that.
I was for a while considering a CANBus. I thought I2C may have been easier, perhaps not?
With a CANBus, how would I go about controlling lights (pin outputs) independently?
I think what I'm getting at is I would like the Arduino to "remember" what it's currently doing, integrate what I've sent it and do that simultaneously. However I don't think this is possible so I guess I would have the controller tell the Arduino what it should be doing until it tell's it to do something different??
I'm sure there are already standard implementations for lights and accessories controlled by CANbus, so I would start by looking for an existing standard protocol and implementation. I seem to remember that there was an open CANbus project based on Arduino (I don't remember what transport it used) and you should be able to locate it - that would probably be a good starting point.
There is no problem designing your Arduino so that each command you send it continues until you instruct it to stop, but in the context of a system where any device could fail or be restarted at any time you need to ensure that whatever else happens your system will quickly and reliably get back to a consistent state. I'd expect a standard protocol to address this issue - while it's also possible to design your own protocol that addresses it, it's not trivial to do and you could easily end up with a system that behaves strangely when something unexpected happens.
Thanks for your help PeterH, I've looked at using the CANBus for the system, however I'm not looking at interfacing with the existing systems within the car, more replacing those systems. But what you've said about devices failing and needing to be restarted is something I had not considered.
I do have one question though, if you set an output pin as being HIGH and then the main loop starts again, does that pin still retain it's HIGH status or reset to LOW?