Pages: [1] 2 3   Go Down
Author Topic: Analysis for Arduino schematic for SD card, flow sensor, Oled, Servo and GPS  (Read 5776 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everybody,

I’m totally new in the Arduino world and this will be my first project. And have no experience with C++ programming and Arduino. However I have reasonable experience programming in Delphi/Pascal and a bit of experience in php and Picbasic. And programmed some PIC’s. So I think I’ll find my way in C. (it just looks a bit more unclear than Delphi).
What I want to make is a gps driven “analog” speedometer for my boat. (a servo will control the needle). And show on a separate display extra information like distance travelled, fuel economy, top speed, etc etc.
For the GPS I want to use a locosys LS20033 (3.3 v) Datasheet: http://www.dpcav.com/data_sheets/LS2003x_gps_v12.pdf
A basic servo to control the speedometer needle (low current draw)
A flowmeter with hall sensors to measure the fuel flow. This thing sends 5V pulses on the output. (I want to use an interrupt to trap the incoming pulses and calculate the fuelflow)
An 128x64 OLED Module SSD1306 in combination with a level shifter.
And eventually a SD card slot to log the GPS Route (but first of all I need to understand the SDI CS configuration with the display and SD card slot)

I will work my project up one sensor at the time, but I made a schematic how I think to hook everything up. So Before I hook up everything I hope someone can review my schematic so I don’t fry the whole thing up.
Especially I don’t understand the oled module connection. But I’ve seen 2 schematics and both hooked it up this way. Tutorial I’ve followed: http://ladyada.net/products/oled12864/
But how will I connect the SD card eventually using the same SDI pins?
It also seems strange to use an analog input to drive an servo, but this tutorial: http://arduino.cc/playground/Learning/SingleServoExample used this port to do it. Apparently you can use analog inputs also as digital outputs.
Finally, the GPS is 3,3V so the ttl output stream will be 3.3V also. Do I need to up the voltage to 5V?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45987
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
A flowmeter with hall sensors to measure the fuel flow. This thing sends 5V pulses on the output. (I want to use an interrupt to trap the incoming pulses and calculate the fuelflow)
Polling should be fast enough, unless the thing sends thousands of pulses a second, in which case the Arduino will accomplish nothing beyond servicing the interrupts.

I had to laugh, though, when you mentioned fuel economy in the same paragraph with boat.

Quote
An 128x64 OLED Module SSD1306 in combination with a level shifter.
A text based LCD would be a lot simpler for a starter.

Quote
But how will I connect the SD card eventually using the same SDI pins?
You mean SPI pins, and the SD card will simply use a different C(hip)/S(lave) select pin. Only one SPI device, defined by the CS/SS pin can be active at a time.

Quote
It also seems strange to use an analog input to drive an servo, but this tutorial: http://arduino.cc/playground/Learning/SingleServoExample used this port to do it. Apparently you can use analog inputs also as digital outputs.
You can, or you can use one of the unused digital pins.

Quote
Finally, the GPS is 3,3V so the ttl output stream will be 3.3V also. Do I need to up the voltage to 5V?
HIGH is anything over 60% of the reference voltage (5V), so 3.3V qualifies. No voltage boost required.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4687
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looking very strange to me is connecting the serial output of your GPS receiver to pin 2 but the signal of your flow meter to pin 1. If you use pin 2 or 3 for the flow meter you'll be able to use an interrupt to count the ticks of the flow meter.

Any of the 6 analog inputs of a standard Arduino can be also a digital input or a digital output.

For the GPS unit you probably need a level converter (a logic HIGH of 2.4 V is not enough for a 5V Arduino).
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45987
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
For the GPS unit you probably need a level converter (a logic HIGH of 2.4 V is not enough for a 5V Arduino).
Where did the 2.4V on a 3.3V device come from?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4687
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@PaulS: From the datasheet. It's the minimal value there so it's the value I have to calculate with when checking for limits. That's why I think a level converter should be used.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Polling should be fast enough, unless the thing sends thousands of pulses a second, in which case the Arduino will accomplish nothing beyond servicing the interrupts.

I had to laugh, though, when you mentioned fuel economy in the same paragraph with boat.
Haha yes, let’s call it “the least unecomical throttle sweet spot calculation”. I’m not sure if polling is fast enough, I don’t want to miss a pulse. I’ts not the only thing the arduino has to do.
Besides counting the flowmeter pulses, he has to decode the gps string for speed and coordinates, calculate distance between coordinates, calculate kilometres per litre, Keep track of the top speed and total distance, save information to eprom, control the servo, put information on the oled screen. All that preferably 10 times a second. and eventually update a GPS log file on a SD card (although this can be done once every 5 seconds or so)
I seriously don’t know how fast a arduino can do his calculations but I don’t want to wait while it could do other things. If this won’t bring the Arduino to his knees, I’m seriously impressed.
Quote
A text based LCD would be a lot simpler for a starter.
Totally agree, I’ve ordered also a two line text module for testing purposes, but for the final project I would like to implement this oled screen for his great readability in sunshine, and the freedom to make it more graphical appealing. If I look at the code it don’t seem to be too complicated. The most complicated stuff is already done in the library :-)
Quote
You mean SPI pins, and the SD card will simply use a different C(hip)/S(lave) select pin. Only one SPI device, defined by the CS/SS pin can be active at a time.
Yes SPI, my mistake. I understand the workings of the SPI, but I don’t understand the wiring done on the oled display. If I look up how I should hook up an SPI device:
http://arduino.cc/en/Reference/SPI
Quote
On the Arduino Duemilanove and other ATmega168 / 328-based boards, the SPI bus uses pins 10 (SS), 11 (MOSI), 12 (MISO), and 13 (SCK).
In my case (based on the tutorial earlier mentioned, and on another example):
-   CS is connected to 12
-   CLK is connected to 10
-   MOSI is connected to 9
-   RS/DC (MOSO???) is connected to 11
This is an connection diagram from the other source (without level shifter)

Totally different connections. Are these connections optional and can you use any of the ports on the arduino? (and define it in the setup part of the code).
Quote
Looking very strange to me is connecting the serial output of your GPS receiver to pin 2 but the signal of your flow meter to pin 1. If you use pin 2 or 3 for the flow meter you'll be able to use an interrupt to count the ticks of the flow meter.
Thanks! I probably have mistaken interrupt 1 with pin 1
Quote
@PaulS: From the datasheet. It's the minimal value there so it's the value I have to calculate with when checking for limits. That's why I think a level converter should be used.
Isnt this probably the minum voltage for the gps to do his job? If I feed it 2,4, the “high” will be 2,4. But if I feed it 3,3v the “High” will be 3,3v? It probably won’t harm the Arduino for trying a lower voltage ;-)

Thanks all for the advice!
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45987
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
From the datasheet. It's the minimal value there so it's the value I have to calculate with when checking for limits. That's why I think a level converter should be used.
It's the minimum voltage that the GPS functions at, true. It is not the actual voltage output if the GPS is powered at 3.3V, though.

The actual voltage output will match the input voltage (or close enough).

Quote
I’m not sure if polling is fast enough, I don’t want to miss a pulse. I’ts not the only thing the arduino has to do.
I'd try it with polling, first. The number of pulses per second, and the width of the pulse determine how long the Arduino has to detect that the pin is HIGH.

If you go with interrupts, because the Arduino isn't fast enough to poll, something else is going to suffer.

Quote
-   CS is connected to 12
Why? 12 is MISO (Master In, Slave Out). CS should be the C(hip)S(elect) pin, so it should be connected to 10.
Quote
-   CLK is connected to 10
Why? 10 is the slave select pin. The CLK (clock) should be connected to 13 (S(lave)C(loc)K).

Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I’m not sure if polling is fast enough, I don’t want to miss a pulse. I’ts not the only thing the arduino has to do.
Why? 12 is MISO (Master In, Slave Out). CS should be the C(hip)S(elect) pin, so it should be connected to 10.
Quote
-   CLK is connected to 10
Why? 10 is the slave select pin. The CLK (clock) should be connected to 13 (S(lave)C(loc)K).
You have exactly the same questions as I have. But if you look at the tutorial, this is the way he hooked it up.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well guy’s just a quick update. I must admit, I’m seriously impressed by the capabilities of the Arduino. Although I’m running towards the limitations.

I can read the fuelflow sensor by a Hardware interrupt, the GPS receiver with the Hardware Serial, read a temperature sensor (analogue in port). Drive a graphical Oled screen (128x64px) with Hardware SPI and control a servo for the analogue speed needle.

The graphical display displays now:

-Fuel economy (also with a progress bar)
-Fuel flow (also with a progress bar)
-Top speed all time
-Top speed trip
-Amount of litres burned trip
-Amount of litres burned total
-Trip Distance travelled in KM
-Total distance travelled
-Speed
-Outside temperature

Complete with custom font and nice icons! Not bad for a first project hè!?

Did a lot of learning, but now the project is running towards the limitations of the Arduino. I want to add a SD card, but I think I’m running low on available memory. The Oled alone uses 1k of memory buffer, leaving me just 1k for the rest from the programme. If I only ad:
Code:
#include <SD.h>
To the code, the oled totally get scrambled with errors, and resets the system. It’s probably reading writing memory locations it not supposed to write. I think that the 537 bytes of memory buffer that the SD need is Way too much. With the library I’m also almost hitting the 32k flash memory mark. So I think the extra SD card is a bit too much.
Thinks I can try to make this work, is to find a way to dump the oled memory buffer when I want to write to the SD card, and reinitialize the oled buffer when I’m done. But I don’t know how to do that, since the memory buffer part is implemented in the oled (ssd1306) library.

Option 2: upgrade to a Arduino Mega

Option 3: Using a second Arduino to handle just the SD card stuff and communicate with the serial port. This is the option I’ll go for I think. And use only the ATmega328 chip when its programmed.

Any thoughts?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4687
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First of all: I'd go for the Mega2560 (done the same thing for my car project).

If you wanna connect two Arduinos I'd not use the serial interface for the inter-comm, but the I2C. This way you have a fast communication which is extensible for another Arduino or I2C sensor if need arises. Also, in my experience it's more stable than anything done with SoftwareSerial (the UNO has just one hardware serial port).
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can’t even use softwareserial (learned that the hard way ;-) ) The Servo library does not work when you also use the softwareserial library. Apparently the softwareserial disables a hardware timer what is used by the Servo library and causes the servo to jitter.

My idea was to use the hardware serial RX to receive the GPS signal, and the TX to communicate to the other Arduino (one way communication). Maybe one digital pin to easily confirm that a package is arrived in good condition.

The reason for my preferable choice to use a second Arduino instead of upgrading the whole project to a mega, is that I’ts much cheaper. I want to program the second Arduino and pop the ATmega328 out of the socket to use the chip standalone. Besides the voltage I think I can also steal the clock oscillator signal from the first Arduino.

Cost extra ATmega328: about 5€

Cost Arduino Mega: about 50€

I’ve looked into I2C communication, but this needs also an extra library (Wire.h). Don’t know how much RAM / Flash it’s going take extra, but I’m allready at its limits. And the serial is allready loaded.

Maybe I can optimise the source code. Like I stated in the first post, I’m a beginner programming in C. But I don’t think I can free 0.5k for the SD card buffer.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4687
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Besides the voltage I think I can also steal the clock oscillator signal from the first Arduino

I'm not a specialist in these things but as far as I know, this is not possible. You have to give the ATmega at least a resonator (better a crystal) and two capacitors, a button or a capacitor for the reset line is probably also unavoidable. But you're right, that's quite a bit cheaper than a Mega.

Quote
I’ve looked into I2C communication, but this needs also an extra library (Wire.h).

That's correct but this is a slim one because most of it is handled in hardware. And this way you get a two way communication and so you can give more work to your second "Arduino".

Quote
Maybe I can optimise the source code.

If you post your code maybe we can help you optimise :-).
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I’ve no problem posting the source code, but I have to clean it up (there’s a lot of commented out code) and translate it to English first (Some variables and most of my own comments are in Dutch).
I’m going to look if I can make a I2C connection to a second arduino without overflowing the memory. Such a shame the compiler can’t give me exact memory statistics. It’s a bit of trial and error. Hoping I have no memory leaks.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tried to add the wire library and Wire.begin() in the setup part. Just with those two codes het hangs up the Arduino. Probably uses to much RAM. First thing to do now is clean up and optimize the code I guess.
I think I can save a bit of RAM by PROGMEM all used strings. But when I convert my strings in:
Code:
F("String in flash")
I get the error:
“error: conversion from '__FlashStringHelper*' to non-scalar type 'String' requested”
So, I have to look into that first.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4687
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You cannot use the F() macro for all strings, but it's a good solution for constant strings used as direct parameters to any Print class (Serial, EthernetClient and the like).

BTW: you should get rid of the String class as it's a memory hog and every operation on it fragments you memory a bit more. Try to convert your code to use character arrays instead of the String class.
Logged

Pages: [1] 2 3   Go Up
Jump to: